How to script setting Computer Name to AD Client ID

New Contributor

I've been told many times I'm going about this the wrong way, but I really want a simple solution that doesn't require a bunch of scripts, so....

We have all our devices in DEP. They are set to a prestage enrollment that has the directory settings set to Bind to AD and set the Client ID to LTM-$USERNAME at enrollment. This works fantastic. Machine starts up, goes to the management screen which requires authentication, user authenticates, machine is bound to AD with the correct name and shows in both Directory Utility as well as AD with the correct name.

The problem is, for whatever reason, this doesn't set the Computer Name to be that. The Machine shows up in JAMF as MacBook Air. A quick check of scutil shows the computer name, host name, and local host name are all MacBook Air.

So, assuming this isn't a bug or is "working as designed" which it really should be setting those all to the same thing at the bind, how do you call out the Client ID to write a script to set the Computer Name to be the same after it is bound?


New Contributor III

We use this as the first policy that runs once the computer is enrolled. The computer still enrolls into jamf as MacBook Pro etc., but this then changes the name. We follow this up with a recon command. It seems to work. We use the serial number, so I assume amendingthe script for your naming convention should work.


#First, get the computer name
COMPUTERNAME=`scutil --get ComputerName`

#Second, get the Serial Number
SERIALNUMBER=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'`

    echo "no change"
        /usr/local/jamf/bin/jamf setComputerName -useSerialNumber