Posted on
04-08-2015
09:27 AM
- last edited
2 weeks ago
by
kh-richa_mig
Hi,
Just wanted to share this script I finally got to work in our environment where we keep having issues with MAC machines connecting to the internal office Wi-Fi which is managed by Windows AD. The script pretty much cleans up Keychain Access from specific Wi-Fi Access Point name as well as cleans up specific Wi-Fi profile and re-registers specific local mobile profile.
While this script may not be suitable for different locations, I had a hard drive finding on how to clear the Keychain Access using JSS script and finally figured it out!
WIFISSIDNAME - is the specific Wi-Fi Access Point
WIFISSIDNAME.mobileconfig - is the mobile config used in our environment
Script:
#!/bin/sh
wservice=`/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)'`
device=`/usr/sbin/networksetup -listallhardwareports | awk "/$wservice/,/Ethernet Address/" | awk 'NR==2' | cut -d " " -f 2`
sudo networksetup -removepreferredwirelessnetwork "$device" WIFISSIDNAME
echo “Deleted WIFISSIDNAME WiFi Profiles”
security delete-generic-password -l WIFISSIDNAME "/Users/$USER/Library/Keychains/Login.keychain"
echo “Deleted WIFISSIDNAME from Keychain Access”
sudo profiles -R -F /Users/Shared/MacConfiguration/WIFISSIDNAME.mobileconfig
echo “Deleted existing wifi certificate”
sudo profiles -I -F /Users/Shared/MacConfiguration/WIFISSIDNAME.mobileconfig
echo “Added wifi certificate”