Running rename script on initial enrollment (check AD)

simotarta
New Contributor

Hi everyone.
I know very little about bash and need your help.
I need a script that renames the Mac during the first initialization. The script must check from the active directory what is the first available name to assign it to the new machine. For simplicity, in the AD, computers are renamed "mc-xxx" (xxx = number from 001 to 999). The script should look for the first missing number from the list and assign it to the new machine.

Thank you all

Simone

1 REPLY 1

dubel
New Contributor III

We use the Serial number with a short company name identifer in-front, with the example below I used MC, so the Computer name will be MCSERIALNUMBER or you could just use the SERIALNUMBER. But you want to make sure you keep it at 15 chars or under. Then I run the BIND afterwards via a custom trigger

#!/bin/sh
#

serial=`/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial\ Number\ \(system\)/ {print $NF}'`
/usr/sbin/scutil --set ComputerName "MC${serial}"
/usr/sbin/scutil --set LocalHostName "MC${serial}"
/usr/sbin/scutil --set HostName "MC${serial}"
killall System\ Preferences
sudo jamf policy -trigger BINDCUSTOMTRIGGER