Skip to main content
Solved

Computer Name Script


Forum|alt.badge.img+7

I use a Policy that runs the script below to name our MacBooks to the machine's S/N that runs after enrollment and lately it stopped working.  It might be since Ventura came out or one of the revision, but I cannot confirm.  I can run the commands manually so they commands haven't changed.  Any suggestions would be great.

 

#!/usr/bin/env bash

# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')

# Set the ComputerName, HostName and LocalHostName
scutil --set ComputerName $sn
scutil --set HostName $sn
scutil --set LocalHostName $sn

Best answer by mm2270

I can't say why the above would not be working. It could be a timing thing. With computer rename scripts, sometimes if they kick in too quickly they don't take effect and/or the original name sticks around, making it look like the command failed. it may also be that you have to clear the cache after doing the rename. I run this command in my script right after naming the computer.

/usr/bin/dscacheutil -flushcache

Also, you can try using the jamf binary itself to do the renaming, which may yield better results.

/usr/local/bin/jamf setComputerName -useSerialNumber

 

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+7
  • Author
  • Contributor
  • 47 replies
  • April 25, 2023

Forgot to include that the Policy shows Complete with no errors in Jamf Pro.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • April 25, 2023

I can't say why the above would not be working. It could be a timing thing. With computer rename scripts, sometimes if they kick in too quickly they don't take effect and/or the original name sticks around, making it look like the command failed. it may also be that you have to clear the cache after doing the rename. I run this command in my script right after naming the computer.

/usr/bin/dscacheutil -flushcache

Also, you can try using the jamf binary itself to do the renaming, which may yield better results.

/usr/local/bin/jamf setComputerName -useSerialNumber

 


Forum|alt.badge.img+7
  • Author
  • Contributor
  • 47 replies
  • April 25, 2023
mm2270 wrote:

I can't say why the above would not be working. It could be a timing thing. With computer rename scripts, sometimes if they kick in too quickly they don't take effect and/or the original name sticks around, making it look like the command failed. it may also be that you have to clear the cache after doing the rename. I run this command in my script right after naming the computer.

/usr/bin/dscacheutil -flushcache

Also, you can try using the jamf binary itself to do the renaming, which may yield better results.

/usr/local/bin/jamf setComputerName -useSerialNumber

 


I added the flush dns command to the scirpt and also put a jamf recon at the end and it worked.  Thanks for the recommendation.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings