Easy way to rename mac`s

Captainamerica
Contributor II

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?

7 REPLIES 7

m_donovan
Contributor III

Are they bound to Active directory or something similar?

sdagley
Esteemed Contributor II

@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)

Captainamerica
Contributor II

They are not bound to AD

sdagley
Esteemed Contributor II

@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.

kcranford
New Contributor II

You could just use Jamf Remote. There is an option in there to change the computer name.

sharriston
Contributor III

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

jcarr
Release Candidate Programs Tester

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).