renaming machines globally

New Contributor III


I'm looking for a way to rename my machines based on global location (UK, APAC, US, EMEA) and username

I have a script that I inherited that is using an API but it's crapped out and I'm not sure why. I'm trying to find a way to automate this after enrollment and/or at check-in.

I'm sure I can't be the only one who has faced this situation, any help would be appreciated.


Valued Contributor II

How are you tracking their location? Are they being assigned to groups or buildings? I wanted a way to auto-name Macs using a naming scheme that I came up with that would add the users' first and last initials to the end of the computer name. I wrote a script after getting some help from Jamf Nation that renames Macs using my naming scheme. You may be able to use something like this script to do what you need. I have several clients, so the script says to replace "XX" with the client company's initials before using the script.


#Rename the Mac using the first and last initial of the user's name. Before using this script, replace "XX" in line 12 with the client company's initials

#Who is the current logged in user?
currentUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
echo $currentUser

#Generate computer name - Replace "XX" with the client company's initials
firstInitial=$(finger -s $currentUser | head -2 | tail -n 1 | awk '{print toupper ($2)}' | cut -c 1)
lastInitial=$(finger -s $currentUser | head -2 | tail -n 1 | awk '{print toupper ($3)}' | cut -c 1)

echo $computerName

#Send the computer name to inventory record
scutil --set ComputerName $computerName
scutil --set LocalHostName $computerName
scutil --set HostName $computerName

#Clear the directory service cache then run a current inventory to send the new Mac name to Jamf Pro
dscacheutil -flushcache
/usr/local/jamf/bin/jamf recon

#Howie Isaacks with help from Jamf Nation | F1 Information Technologies | 09/27/21

 I have a policy that runs this script after enrollment just before all of the app install policies start running. I also used it to mass rename Macs when I came up with the new naming scheme.