Posted on 05-16-2023 08:08 AM
Hi, I tried using JAMF school to set the names for all new devices.
Under device placeholder I updated "Set Device Name" in JAMF and the Macbook device Computer Name did changed but when I use terminal to check hostname is it different. Is there a way to change all names at once?
Thank you
Posted on 05-16-2023 12:31 PM
I use JAMF Pro if that matters for this. I do this with a script and the script runs on recurring check in targeting a smart group of devices who's hostname does not match their serial number.
#!/usr/bin/env bash
#*=============================================================================
#* Script Name: Configuration: Set Hostname
#* Created:
#* Author:
#*=============================================================================
#* Purpose: Requests input and renames computer based on Naming Convention
#*=============================================================================
#*=============================================================================
#* REVISION HISTORY
#*=============================================================================
#* Date:
#* Author:
#* Issue:
#* Solution: N/A
#*=============================================================================
#*=============================================================================
#* GLOBAL VARIABLES
#*=============================================================================
DIV1='echo ####################################################################'
DIV2='echo --------------------------------------------------------------------'
DIV3='echo ....................................................................'
ActiveUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }' | tr "[a-z]" "[A-Z]"`
ActiveUserRealName=`dscl . -read /Users/$ActiveUser | grep RealName: | cut -c11-`
if [[ -z $ActiveUserRealName ]]; then
ActiveUserRealName=`dscl . -read /Users/$ActiveUser | awk '/^RealName:/,/^RecordName:/' | sed -n 2p | cut -c 2-`
fi
computerName=$(scutil --get ComputerName)
hostName=$(scutil --get HostName)
localHost=$(scutil --get LocalHostName)
serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
serialNumberII=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | tr -d '"')
#*=============================================================================
#* FUNCTIONS
#*=============================================================================
userInfo () {
echo; $DIV1
echo "User Information:"
if [[ "$ActiveUserRealName" == "$ActiveUser" ]]; then
echo "$ActiveUserRealName (Local Admin)"
else
echo "$ActiveUserRealName ($ActiveUser)"
fi
$DIV1
}
#*=============================================================================
#* SCRIPT BODY
#*=============================================================================
userInfo
## Check & Update Computer Name
if [ "$computerName" == "$serialNumber" ]
then
echo "Computer name matches serial number, $serialNumber"
else
echo "Current Computer Name: $computerName"
echo "Computer Name does not meet standards"
echo "Changing Computer Name to match Serial Number"
scutil --set ComputerName "$serialNumber"
fi; $DIV2
## Check & Update Host Name
if [ "$hostName" == "$serialNumber" ]
then
echo "Host Name matches serial number, $serialNumber"
else
echo "Current Host Name: $hostName"
echo "Host Name does not meet standards"
echo "Changing Host Name to match Serial Number"
scutil --set HostName "$serialNumber"
fi; $DIV2
## Check & Update Local Host
if [ "$localHost" == "$serialNumber" ]
then
echo "Local Host matches serial number, $serialNumber"
else
echo "Current Local Host: $localHost"
echo "Local Host does not meet standards"
echo "Changing Local Host to match Serial Number"
scutil --set LocalHostName "$serialNumber"
fi; $DIV2
## Final Check
computerNameII=$(scutil --get ComputerName)
hostNameII=$(scutil --get HostName)
localHostII=$(scutil --get LocalHostName)
echo ""
echo "Serial number: $serialNumber"
echo "Computer Name: $computerNameII"
echo "Host Name: $hostNameII"
echo "Local Host: $localHostII"
if [[ "$computerNameII" == "$serialNumber" ]] && [[ "$hostNameII" == "$serialNumber" ]] && [[ "$localHostII" == "$serialNumber" ]]
then
echo "Computer Name satisfies naming standards"
$DIV1; exit 0
else
echo "Computer does not meet naming standards"
echo "More troubleshooting will be necessary."
$DIV1; exit 1
fi
## Perform final Recon to update computer name on Jamf
sudo jamf recon
#*=============================================================================
#* END OF SCRIPT
#*=============================================================================
Posted on 05-19-2023 08:59 AM
Thank you for the script.
Is it possible for it to lookup to a Google Spreadsheet it will get the serial number and set devices name individually? e.g: serial 12345 > Air1 and 6789 >Air2
Posted on 05-19-2023 08:57 AM
Thank you for the script.
Is there a way, if i have 100 MacBook and a google sheet of all serial number and desire name for each machine.
Can I call a lookup to Google sheet and base on serial number it can change all the devices automatically.
Thank you