Posted on 12-23-2022 02:53 AM
Solved! Go to Solution.
Posted on 12-27-2022 11:47 PM
Got it working via a workaround script:
#!/bin/bash
#Grab current computer name
computername=$(scutil --get ComputerName)
echo "Computername: $computername"
#Grab current LocalHostName
LocalHostName=`/usr/sbin/scutil --get LocalHostName`
echo "LocalHostName: $LocalHostName"
if [ "$computername" == "$LocalHostName" ]; then
echo "Computername and LocalHostName is a match"
else
echo "Computername and LocalHostName do not match"
echo "$computername" >> /Users/Shared/CorrectHostName.txt
File="/Users/Shared/CorrectHostName.txt"
Hostname=$(cat "$File")
echo "LocalHostname will be changed to: $Hostname"
sudo scutil --set LocalHostName "$HostName"
sleep 3
LocalHostNameChanged=`/usr/sbin/scutil --get LocalHostName`
echo "LocalHostName after change: $LocalHostNameChanged"
rm /Users/Shared/CorrectHostName.txt
fi
Posted on 12-23-2022 05:23 AM
we have used the following for the last few years. I do not recall seeing that error. Maybe order matters or the jamf command is masking it in our script,hth
scutil --set ComputerName $SerialNumber
scutil --set LocalHostName $SerialNumber
scutil --set HostName $SerialNumber
jamf setComputerName -name $SerialNumber
jamf recon
Posted on 12-26-2022 11:37 PM
Like I said, there is nothing wrong with the script itself as on half of my Mac's it's changing the names just fine. It's just for a couple of Mac's where we receive the error: SCPreferencesSetLocalHostName() failed: Invalid argument
Manual changing is not an option.
Posted on 12-27-2022 11:47 PM
Got it working via a workaround script:
#!/bin/bash
#Grab current computer name
computername=$(scutil --get ComputerName)
echo "Computername: $computername"
#Grab current LocalHostName
LocalHostName=`/usr/sbin/scutil --get LocalHostName`
echo "LocalHostName: $LocalHostName"
if [ "$computername" == "$LocalHostName" ]; then
echo "Computername and LocalHostName is a match"
else
echo "Computername and LocalHostName do not match"
echo "$computername" >> /Users/Shared/CorrectHostName.txt
File="/Users/Shared/CorrectHostName.txt"
Hostname=$(cat "$File")
echo "LocalHostname will be changed to: $Hostname"
sudo scutil --set LocalHostName "$HostName"
sleep 3
LocalHostNameChanged=`/usr/sbin/scutil --get LocalHostName`
echo "LocalHostName after change: $LocalHostNameChanged"
rm /Users/Shared/CorrectHostName.txt
fi