Device Name automatically

alexthefourth
New Contributor

Ive been browsing through different articles but havent quite found my answer. Im looking for a way to automatically name the device, our naming convention is serialnumber-username and the intial user that we create during setup is the username intended for the computername.

Can both of those values be pulled from the system and then I can just run a script using scutil to change hostname and computername?

1 REPLY 1

jcarr
Release Candidate Programs Tester

Device names are broadcast in the clear so I would avoid using PII in a device name. Just my $0.02

That being said, you can use the jamf binary to set the name. Something like this should work:

#!/bin/sh

loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')

serialNumber=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')

/usr/local/bin/jamf setComputerName -name "$serialNumber-$loggedInUser"

exit 0