Trying to find the best way to rename computers after enrollment

MBlank
Contributor

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. 

3 ACCEPTED SOLUTIONS

ryan_ball
Valued Contributor

@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.

View solution in original post

Yes, if you get your first name variable, you will just plug that into where you are setting the computer name variable 

View solution in original post

computerName=$internalNamingScheme-$modelName-$fname-$serial

View solution in original post

43 REPLIES 43

MBlank
Contributor

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?

computerName=$internalNamingScheme-$modelName-$fname-$serial

All set! That worked! Thanks again! 🙂

yjian
New Contributor III

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