Name change on Jamf pro

danlaw777
Contributor III

If i change the name of the computer on the dashboard, will that propagate down to the machine in question? I looked thru several old posts pre 2016, and it looks like this was a change request. was it ever done?

20 REPLIES 20

Hugonaut
Valued Contributor II

1/13/20 - Edit: My response is not completely true, @jimmy.vance from jamf posted a solution below that does exactly what danlaw777 was looking for.



Original Post: No, it is the opposite.

Whatever the computer name is at the Computer level, it will reflect in Jamf.

For example If you changed the computer name in the Jamf Dashboard and it is different than what the computer is actually named, at the next check-in the Jamf Dashboard will revert to & or reflect the Computers Name.

You need to change the name of the computer at the computer level.

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

danlaw777
Contributor III

I just found that out, i got impatient and named a mac with 2 different names and the 1 that was local took control.

now i just have to figure out a good way to write a script that will rename them .

Hugonaut
Valued Contributor II

@danlaw777 you can start with this, it's all you need. the sudo jamf recon at the end of the script will update jamf after the computers renamed so it reflects the name change straight away

#!/bin/bash

ComputerName="NameHere"

scutil --set HostName $ComputerName
scutil --set LocalHostName $ComputerName
scutil --set ComputerName $ComputerName

sudo jamf recon
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

danlaw777
Contributor III

does this prompt for end user input?

Hugonaut
Valued Contributor II

No, it does not, are you seeking a user input text box for renaming?

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

Hugonaut
Valued Contributor II

@danlaw777 heres a small applescript to get the job done

#!/usr/bin/osascript

set computername to text returned of (display dialog "Please type Computer Name" default answer "")

do shell script "sudo scutil --set HostName " & quoted form of computername

do shell script "sudo scutil --set LocalHostName " & quoted form of computername

do shell script "sudo scutil --set ComputerName " & quoted form of computername

do shell script "sudo jamf recon"
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

danlaw777
Contributor III

im hoping to have minimal user input. my goal would be: greetings, please input your 3 character location code: XXX
then the script takes that codeand adds the serial number at the end
ie: xxx-ewjfnwfnwen

once thats done run recon to update jamfpro

Hugonaut
Valued Contributor II

this will do it @danlaw777

#!/usr/bin/osascript

set locationcode to text returned of (display dialog "Please input your 3 character location code." default answer "" with title ("Employee Location Code") with icon alias (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns") buttons {"Continue"} default button "Continue")

set serialnumber to do shell script "system_profiler SPHardwareDataType|grep 'Serial Number' -m1|cut -d: -f2|cut -c 2-13"

do shell script "scutil --set HostName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "scutil --set LocalHostName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "scutil --set ComputerName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "sudo jamf recon"
________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

drtaru
New Contributor III

You can also lock the computer name via Jamf. If the Jamf binary sets the computer name it disallows the end user from changing it. I have modified Hugonauts script to make the change via jamf as well, which will prevent the name from being edited.

#!/usr/bin/osascript

set locationcode to text returned of (display dialog "Please input your 3 character location code." default answer "" with title ("Employee Location Code") with icon alias (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns") buttons {"Continue"} default button "Continue")

set serialnumber to do shell script "system_profiler SPHardwareDataType|grep 'Serial Number' -m1|cut -d: -f2|cut -c 2-13"

do shell script "scutil --set HostName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "scutil --set LocalHostName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "scutil --set ComputerName " & quoted form of (locationcode & "-" & serialnumber)

do shell script "sudo /usr/local/bin/jamf setComputerName -name" & quoted form of (locationcode & "-" & serialnumber)

do shell script "sudo jamf recon"

Hugonaut
Valued Contributor II

i like that addition! very nice drtaru

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

danlaw777
Contributor III

well, im not sure how i screwed it up, but when i run this, i dont get a prompt to insert the code, the only thing i see is that it runs, and then shows complete......

jimmy_vance
New Contributor
New Contributor

You can make use of the Reset Computer Names option in the Maintenance payload in Computer Policies. As stated, it will "Change the computer name on computers to match the computer name in Jamf Pro." Hope that helps!
8fd2bff14c414579b074a4e4f64f679a

danlaw777
Contributor III

this was perfect, no interaction needed! thanks !

Hugonaut
Valued Contributor II

haha & here we are making little interactive applescripts & jamf has it all done already in the gui +1 to Jamf. learn something new everyday.

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

danlaw777
Contributor III

all it takes is for some new guy who doesnt know his A$$ from a whole in the wall to ask!

Ke_ReM
New Contributor III

You can also use the Jamf Remote app to change names via JSS without pushing any policies which probably utilises same maintenance script.

1> First rename the device in your JSS.
2> Open the Jamf Remote app > Computers tab > find your device and ensure it is ticked.
3> Advanced TAB > Maintenance, tick the FIX computer Names box
4> Click Go

rpayne
Contributor II

We name all machines to their serial with the following script:

#!/bin/sh

#get serial number
serial=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')

# Set Hostname using variable created above
echo "Setting computer name to $serial locally..."
scutil --set HostName "$serial"
scutil --set LocalHostName "$serial"
scutil --set ComputerName "$serial"


exit 0

jhuls
Contributor III

Just keep in mind that if the Mac is in active directory that this Reset Names feature will not rename it in AD.

danlaw777
Contributor III

i do, fortunately, we aren't binding our macs to AD

scottb
Honored Contributor

@rpayne - that's a great one for when a client has no clue what they want to do! Which is often, or when there is no LDAP, etc.

Thanks for the post.