Skip to main content

We currently deploy a WPA2 PSK via a configuration profile, we are finding a lot of client Macs are ending up with our client machine wifi at a lower priority than the guest wifi so suddenly nothing works and they get captive portal pop ups.



Can anyone help with a way to:




  1. Script the change of priority/index of a remembered wireless network?

  2. Reinstall a computer level config profile

  3. Script the addition of a wifi network without storing the PSK in plain text as part of a one line networksetup command?



Help would be greatly appreciated!



Thanks,
Christian

Hey @cdwyersg



You can use the following commmands to modify priorities of wifi.



#!/bin/sh

currentUser=$(stat -f%Su /dev/console)
currentUserUID=$(dscl . read /Users/$currentUser UniqueID | awk {'print $2'})
wifi=$(/usr/sbin/networksetup -listallhardwareports | grep -A 1 Wi-Fi | grep Device | awk '{print $2}')
SSIDcheck=$(/usr/sbin/networksetup -listpreferredwirelessnetworks $wifi | grep $4 | awk {'print $1'})

echo "Wi-Fi on device port $wifi"
echo "Preferred wireless Network $SSIDcheck"
echo "Policy running for $currentUser"


#############################################################
######## Removes SSID from Preferred Wireless List #########
#############################################################

if [ "$SSIDcheck" = "$4" ];then
echo "Removing $4 from Preferred Networks List"
/usr/sbin/networksetup -removepreferredwirelessnetwork $wifi $4
echo "Adding $4 to number 1 spot for Preferred Networks List"
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $wifi $4 0 WPA2 $5
else
echo "$4 not in Preferred Networks List, adding to number 1 spot"
/usr/sbin/networksetup -addpreferredwirelessnetworkatindex $wifi $4 0 WPA2 $5
fi

Pardon my ignorance on this, where do I replace the Wifi SSID we're trying to remove and/or the one we're trying to make top priority?


@jjones Had a good post here: https://jamfnation.jamfsoftware.com/discussion.html?id=17858


How about this exact same issue but on iOS???


@cruess If you need to stop a device from connecting to a network you could push out a profile to the device with the wireless login and password and then remove the profile and that should stop the device from connecting.


Can“t get any of the scripts to change the order of SSIDs I've found to work on Sierra.
Anybody have a script or trick that works?


I had good luck with this one at https://gist.github.com/pudquick/fcbdd3924ee230592ab4#file-reorder_wifi_alt-py-L5 after reading about it here
https://www.jamf.com/jamf-nation/discussions/18223/re-order-wifi-preferred-networks