Posted on 09-16-2021 07:53 AM
I'm currently testing Jamf and have everything working as I want with with the exception of figuring out the best way to rename computers after they are setup.
Currently I'm using Jamf with Jumpcloud pushing the user accounts for staff to an employee's computer however I'm stuck with the default computer name of Macbook Pro. I'm trying to figure out the best way to script this or use a policy that runs after the user is setup to that a machine can be renamed for username-Macbook Pro.
I'm wondering what the best way is to accomplish the renaming task so it can be automated and not have to be done manually each time a computer is deployed .
Thanks for any suggestions.
Solved! Go to Solution.
Posted on 09-16-2021 09:22 AM
@mm2270 basically gave the entire answer. His code in a script would be:
#!/bin/bash
# Get the logged in username
logged_in_user=$( echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name 😕 && ! /loginwindow/ { print $3 }' )
# Create a string
comp_name="${logged_in_user}-MacBook Pro"
# Rename the Mac using the jamf command line tool
/usr/local/bin/jamf SetComputername -name "$comp_name"
exit 0
Just take that, create a file named rename.sh using a Text Editor like Visual Studio Code, then upload that to your Jamf Pro and create a policy leveraging that script that runs once at check-in most likely as you want the user to actually be logged in when it runs.
Posted on 10-22-2021 07:42 PM
Yes, if you get your first name variable, you will just plug that into where you are setting the computer name variable
10-25-2021 07:26 AM - edited 10-25-2021 07:27 AM
computerName=$internalNamingScheme-$modelName-$fname-$serial
Posted on 10-25-2021 07:24 AM
One thought occurred to me. It's unlikely but any ideas to avoid duplicate names besides appending the serial #? Which I assume would be this line modified:
computerName=$internalNamingScheme-$modelName-$fname
To:computerName=$internalNamingScheme-$modelName-$fname-$serialNumber"
Also if you don't mind does that modified line look good?
10-25-2021 07:26 AM - edited 10-25-2021 07:27 AM
computerName=$internalNamingScheme-$modelName-$fname-$serial
Posted on 10-25-2021 09:46 AM
All set! That worked! Thanks again! 🙂
Posted on 05-08-2023 06:27 AM
Is there a way to rename computer name base on csv file with MAC address?
MAC: Comp_Name
1c:57:dc:29:2d:1a AirBook-0001
2c:57:dc:30:2d:1b AirBook-0002
3c:57:dc:31:2d:3b AirBook-0003