Set Name with department abbreviation and serial number

rcs336
New Contributor

Im looking for an easy way to set the computer name during the imaging process to have the department and then the serial number of the computer. Ive done some research but couldn't really find anything.

7 REPLIES 7

bpavlov
Honored Contributor

You would have to script something like that.

One way I can think of, in Casper Imaging write the initials of the Dept in the computer name field then have a firstboot script that collects the computer name using and comes it with the serial number:

#Get computer name from JSS
JSSComputerName="$(/usr/bin/jamf getComputerName)"

#Get computer serial number
SerialNumber="$(/usr/sbin/system_profiler SPHardwareDataType | grep "Serial Number (system)" | awk '{print $4}')"

#Combine both computer name and serial number
NewComputerName="$JSSComputerName$SerialNumber"

#Rename computer in JSS
/usr/bin/jamf setComputerName "$NewComputerName"

Just a fair warning, I haven't tested this. And there may be other ways to tackle this as well, but it's the first thing that came to mind.

mm2270
Legendary Contributor III

As I think was mentioned by someone else on another similar thread from a few months back (and I admittedly had forgotten about), the jamf binary can do this all by itself:

#!/bin/sh

prefix="department_name"

/usr/sbin/jamf setComputerName -useSerialNumber -prefix "$prefix"

The above will set the Computer name to be department+serial number. You could add some delimiter into the prefix if needed to have some separation, like a dash for example.

bentoms
Release Candidate Programs Tester

@rcs336 What @mm2270 is what I usually recommend.

One thing though, are you binding to AD? If so, you may want to think carefully about name length & also maybe have serial 1st as then it should be unique (incase the department gets abbreviated).

rcs336
New Contributor

I just tried what you suggested @mm2270 and not sure what I did wrong. I used the JSS Management Site and added a script then included that scrip in my configuration. Is there any more info you could give me?

bentoms
Release Candidate Programs Tester

@rcs336 "JSS Management Site"?

rcs336
New Contributor

The website you use to manage casper settings. Sorry not sure what else to call it.

mm2270
Legendary Contributor III

That's often referred to as just the JSS (JAMF Software Server)
As for adding it in your configuration, I assume you mean your Casper Admin imaging configuration? If so, make sure the script is running after the Mac boots into the imaged OS. Also, you may want to check around on here for best practices regarding system naming scripts and imaging since some of these things need to be done in an exact order and can mess up the process if done too early (or even too late)
Since I don't use Casper Imaging (using DeployStudio with a custom post image process) its hard for me to guide you on exactly when this should run.