Hi there,
Hoping I can entreat the Hive Mind to help me nail down why I'm getting an error in the last part of this script. I'm putting together a self service policy that will run two scripts. One grabs the current computer name as a variable, deletes all the relevant networking plist files in /Library/Preferences/SystemConfiguration, and then renames the computer to its original name. That one is working great.
The second script is where I am having trouble (I split them into two because for no discernible reason, the first part would throw weird errors when they were combined in one script but now it seems to work fine with them separate despite there being no differences in the command statements).
This script creates a new network location, switches to it, and deletes the old one. But I'm having trouble with the last part. I'll include the script below, and the jamf policy log output from a test machine.
#Created by John Geck, 7/21/2023
#Create a new network location and substitute the “CRPUSD” variable below with the name you choose
originallocation="$(networksetup -getcurrentlocation)"
newlocation="CRPUSD"
networksetup -createlocation "$newlocation" populate
sleep 5
#Switch to your new location
networksetup -switchtolocation "$newlocation"
sleep 5
#Delete the original location. This is hard-coded because I couldn't figure out how to call the existing locations and create them as a variable.
networksetup -deletelocation "$originallocation"
#Wait 15 seconds for network to re-establish itself and run a Jamf Recon
sleep 15
jamf recon
#Notify user they need to reboot
osascript -e 'display alert "Reset Successful" message "Please save any open work and restart your computer."'
#END
Here's the Jamf Error:
Details
STEP 1 of 5]
Executing Policy Reset Network Settings (Test)
STEP 2 of 5]
Running script Remove Network Plists (Testing)...
Script exit code: 0
Script result:
STEP 3 of 5]
Running script Reset Network Location...
Script exit code: 0
Script result: populated
found it! Could not get current network location
** Error: Unable to access the System Configuration database. is not a network location name.
** Error: The parameters were not valid.
Retrieving inventory preferences from https://jss.crpusd.org:8443/...
Finding extension attributes...
Locating accounts...
Locating hard drive information...
Locating package receipts...
Locating printers...
Locating plugins...
Searching path: /Library/Internet Plug-Ins
Locating applications...
Searching path: /System/Applications
Gathering application usage information from the JamfDaemon...
Searching path: /Applications
Locating hardware information (macOS 13.4.1)...
Submitting data to https://jss.crpusd.org:8443/...
<computer_id>2166</computer_id>
button returned:OK
STEP 4 of 5]
STEP 5 of 5]