Changing Computer Names

micah002
New Contributor

I'd like to send out a script that will change the computer name from "Jane's MacBook Air" to her short name, which we have configured to look like 21smithj.

I know that I can update those names on systems sending out a script, but how to do I get that to reflect inside the JSS? Does that happen automagically? My fear is that it will revert to the previous name during the next check-in or inventory.

Is there a way to avoid that?

Thank you.

9 REPLIES 9

djdavetrouble
Contributor III

the JSS will reflect the name change after the next inventory.

kbingham
New Contributor III

This is the script I use.

#!/bin/sh
username=`ls -l /dev/console | cut -d " " -f 4`

scutil --set ComputerName "$4""$username"
scutil --set HostName "$4""$username".<domain>
scutil --set LocalHostName "$4""$username"

jamf recon

bjones
New Contributor III

@kbingham

Question do you have a script that works asking the user or tech to type in a unique Hostname which for the life of me cannot be automated if im correct?

asegura
Contributor

This is the script I used in the past that prompted the techs to input the new computer name.

!/bin/sh

Set CocoaDialog Location

CD="/Applications/Utilities/cocoaDialog.app/Contents/MacOS/cocoaDialog"

Dialog to enter the computer name and the create $ASSETTAG variable

rv=($("$CD" standard-inputbox --title "Computer Name" --no-newline --informative-text "Enter the Computer Name (Based on your Naming Convention)" --value-required))
COMPNAME=${rv[1]}

Set Hostname using variable created above

sudo scutil --set ComputerName $COMPNAME
sudo scutil --set LocalHostName $COMPNAME
sudo scutil --set HostName $COMPNAME

Dialog to confirm that the hostname was changed and what it was changed to.

tb=`"$CD" ok-msgbox --text "Computer name updated!"
--informative-text "The computer's hostname has been added to $COMPNAME."
--no-newline --float`
if [ "$tb" == "1" ]; then
echo "User said OK"
jamf setComputerName -name "$COMPNAME"
elif [ "$tb" == "2" ]; then
echo "Canceling"
exit
fi

edullum
Contributor

@kbingham That script seems simple enough. Can you explain it to me? My end goal is to change the name of the mac in those three places, but use the already existing asset tag name that is filled into the asset field in Jamf Pro. Right now, only the name of the Mac is changing and I'm having problems with users trying to log in with their AD accounts. These Macs are bound to AD. I believe the issue is occuring because the NetBIOS name is the same on all the macs that are having issues with logging in.

RalphyIT
New Contributor II

I use The MUT when changing multiple device names its really a breeze, has saved me tons of hours!

https://www.jamf.com/jamf-nation/third-party-products/620/the-mut?view=info

mlev
Contributor

@RalphyIT one thing to note when changing computer names with MUT it simply updates the name in Jamf, and doesn't actually push that down to the device itself. It will change back on next inventory update. You can use the "Reset Computer Name" option for policies (Policies > New > Maintenance > Reset Computer Name) which will take the name from Jamf and actually apply it to the computer. I actually also like to use a very similar script to what @kbingham left above, just a simple scutil for the various names.

MUT works fantastic for Mobile Device names, but that's because it actually issues an MDM command to set and enforce the name upon running, which is not something that's possible at this time via the API (to my knowledge) without generating a policy with the payload mentioned above.

glasgowclyde
New Contributor III

Is there a way for me to remote wipe a Mac but keep the name intact for me to identify after the wipe?

Thank you
(New to JAMF)

salmon
New Contributor III

In the script by kbingham (thank you - nice work), I do not want the username selected but serial number used. What is the option to do that?
I ran the script, but it grabbed root as the name (did the script prior to a user logging in) and I do not want the name to change if another user (like our IT staff) logs in.

I found the answer by DHowel (I believe) SERIALNUMBER=ioreg -l |grep IOPlatformSerialNumber | awk '{print $4}' | cut -d " -f 2 This will pull up serial number.
So with this I will make the changes to the script. Thank you ALL!