Posted on 04-11-2019 06:35 AM
Hey All! I have been working on a section of my provisioning script that names the computer then I'm using the built-in Jamf binding tool after the script runs so the proper name is used. The problem I'm running into is that from time to time the rename won't stick and it'll upload as [localadmin]'s Macbook Pro. Anyone else experienced this?
MachineName="$(/usr/bin/osascript -e 'Tell application "System Events" to display dialog "Enter the Machine Name:" default answer "" with title "Rename Machine" with text buttons {"Ok"} default button 1' -e 'text returned of result')"
sudo scutil --set ComputerName $MachineName
sleep 15
sudo scutil --set LocalHostName $MachineName
sleep 15
sudo scutil --set HostName $MachineName
sleep 30
exit 0
Posted on 04-11-2019 06:58 AM
Where do you have it set to trigger, and are you flushing your policies if it's happening to previously enrolled devices?
The way I have our work flow set up for example is, after prestage enrollment is complete trigger this script
#!/bin/bash
LoggedInUser=$(stat -f%Su /dev/console)
LoggedInUID=$(id -u "$LoggedInUser")
computerName=$(/bin/launchctl asuser "$LoggedInUID" sudo -iu "$LoggedInUser" /usr/bin/osascript -e 'Tell application "System Events" to display dialog "Please enter computer name and click Submit:" default answer "" buttons {"Submit"} with icon caution' -e 'text returned of result' 2>/dev/null)
/usr/sbin/scutil --set ComputerName "${computerName}"
/usr/sbin/scutil --set LocalHostName "${computerName}"
/usr/sbin/scutil --set HostName "${computerName}"
dscacheutil -flushcache
echo "Computer name has been set.."
echo "<result>' scutil --get ComputerName'</result>"
I also have a profile to allow the JAMF agent to act as a privileged user without user interaction: https://github.com/jamf/JamfPrivacyPreferencePolicyControlProfiles
Together this makes a dialog popup after the prestage enrollment screen (the one with the cogs) after about 10 seconds of moving onto the privacy and data section. If it's a previously enrolled device I clear all the policies before starting enrollment.
Edit: Also take note that running sudo in a script changes the environment for the script to root(/) which is probably also a cause of your script failing. Using the PPPC profile from JAMF I linked above will remove the need to sudo to make system changes with scripts as the jamf agent.
Posted on 04-19-2019 11:34 AM
I'm seeing a similar behavior,
Here is the script that I'm using
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u "$loggedInUser")
computerName=$(/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" /usr/bin/osascript -e 'tell application "System Events" to set computerName to text returned of (display dialog "Please Input New Computer Name" default answer "" with icon 2)')
scutil --set ComputerName "$computerName"
scutil --set HostName "$computerName"
scutil --set LocalHostName "$computerName"
**But recently I have been seeing this error:
Actions from policy log:
Executing Policy Enrollment - 75 - Computer Name
Running script enrollment-computerName.sh...
Script exit code: 1
Script result: 74:151: execution error: An error of type -10810 has occurred. (-10810)
Could not open prefs: No such key
SCPreferencesSetHostName() failed: No such key
SCPreferencesSetLocalHostName() failed: No such key
Error running script: return code was 1.