Posted on 12-10-2018 05:59 AM
I have some mac´s that got an wrong Name when they where enrolled. If I rename them in Jamf nothing happens.
So I am looking for a way to remotely be able to rename the mac´s without any user intervention ? - is this somehow possible?
Posted on 12-10-2018 06:08 AM
Are they bound to Active directory or something similar?
Posted on 12-10-2018 06:11 AM
@Captainamerica You can run. script to call the scutil
tool to set a Mac's name. My naming pattern is an L or D prefix (for Laptop or Desktop) and this is the script I run to configure that:
#!/bin/bash
serial=$(ioreg -l | grep "IOPlatformSerialNumber" | cut -d "=" -f 2 | sed -e s/[^[:alnum:]]//g)
model=$(ioreg -l | grep "product-name" | cut -d "=" -f 2 | sed -e s/[^[:alnum:]]//g | sed s/[0-9]//g)
tld="YOUR.DOMAIN.HERE.COM"
# Default to a Desktop
prefixLetter="D"
isMacbook=$(echo $model | grep "Book")
if [[ $isMacbook != "" ]]; then
prefixLetter="L"
fi
isVMware=$(echo $model | grep "VMware")
if [[ $isVMware != "" ]]; then
prefixLetter="V"
fi
case "$prefixLetter" in
"V") # Do nothing to Virtual Machines
echo "VMware VM, skipping rename"
;;
*)
scutil --set ComputerName "$prefixLetter$serial"
scutil --set LocalHostName "$prefixLetter$serial"
scutil --set HostName "${prefixLetter}${serial}.${tld}"
echo "$model"
echo "$prefixLetter$serial"
echo "${prefixLetter}${serial}.${tld}"
;;
esac
Note: This does not address any AD name you may have set for the machine (see the question from @m.donovan)
Posted on 12-10-2018 06:33 AM
They are not bound to AD
Posted on 12-10-2018 06:41 AM
@Captainamerica In that case, the script above would be sufficient. Just modify it for your environment and deploy it via a Jamf Pro Policy to any machines you need to rename.
Posted on 12-10-2018 06:49 AM
You could just use Jamf Remote. There is an option in there to change the computer name.
Posted on 12-10-2018 10:54 AM
I use this script to get the user shortname to be the name of the computer. I add mb to the end because thats how my predecessor did it to distinguish between laptops and iMac.
#!/bin/sh
export LOCALMACHINENAME=$(ls -l /dev/console | cut -d " " -f4)
/usr/sbin/networksetup -setcomputername "$LOCALMACHINENAME""mb"
/usr/sbin/scutil --set ComputerName "$LOCALMACHINENAME""mb"
/usr/sbin/scutil --set LocalHostName "$LOCALMACHINENAME""mb"
/usr/sbin/scutil --set HostName "$LOCALMACHINENAME""mb"
exit 0
Posted on 12-10-2018 11:10 AM
It's probably less of an issue in enterprise, but at least in eduction, one should NEVER use personally identifiable information (e.g. username or real name) for the device name. Since the computer name is broadcast in the clear when connected to a network, it's possible for a bad actor to use that information to know when a particular person is nearby. When that person is a student, on a public hot spot for example, you are putting that student's safety at risk.
Here's an example of a one-line command that can be used with the 'Files and Processes' policy payload:
/usr/local/bin/jamf setComputerName -name "My-School-Mac-$(ifconfig en0 | awk '/ether/{print $2}' | tr -d :’)”;/usr/local/bin/jamf recon
This sets the name to the WiFi MAC address with a text prefix and updates recon (so the inventory record in Jamf Pro matches the computer).