Skip to content

Instantly share code, notes, and snippets.

@MelvinStans
Created February 25, 2019 08:18
Show Gist options
  • Save MelvinStans/ea1404e7c81598fe8383e7ba227c748f to your computer and use it in GitHub Desktop.
Save MelvinStans/ea1404e7c81598fe8383e7ba227c748f to your computer and use it in GitHub Desktop.
Mac network location reset
#!/bin/sh
##########################################################################################
# Create time date stamped log
##########################################################################################
logFile="/private/var/log/OurCompany.log"
log () {
/bin/echo $1
/bin/echo $(date "+%Y-%m-%d %H:%M:%S: ") $1 >> $logFile
}
log "-----"
log "Begin script 100_resetNetworkLocationAndPorts.sh"
log "Adjust Network Locations to correctly add network ports"
sleep 5
##########################################################################################
# Create a temporarily Network location and recreate the Automatic location.
##########################################################################################
networksetup -createlocation TempLoc populate
sleep 5
networksetup -switchtolocation TempLoc
sleep 2
networksetup -deletelocation Automatic
sleep 2
networksetup -createlocation Automatic populate
sleep 5
networksetup -switchtolocation Automatic
sleep 5
networksetup -deletelocation TempLoc
log “Network Location Setup Completed.”
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment