Jump to content

Recommended Posts

Posted (edited)

Hiya, I was looking at making a JAMF rename script which would rename our macs on enrollment or on check-in (once per "computer" or Mac rather!). I remember somewhere I used to be at a big complicated script that renamed it based on a spreadsheet and you had to have a file-share to the csv and setup permissions etc which for people less experienced in Macs and JAMF might be a bit of a pain! I made something which and easy in a sense in about 30 mins and I wanted to share as might help you with your mac deployments and renaming process...

 

I've put a basic one for rename one mac, but the idea is you use the script (but just replicate by copying and pasting section "2a" for each mac you have)...

 

How it works is section "2a" creates a MATCHED=Y value and a NEW_NAME variable IF a serial number match is found. The bit in section 3 then runs the rename script if the MATCHED and NEW_NAME variables are created in section 2a.

 

"

#!/bin/bash

 

# 1 - Get the Mac's serial number


SERIAL=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')
echo $SERIAL

 

# 2 - List TTA Mac Names and there serial numbers in query below.

 

# 2a - Compare Mac Serial and Mac Asset and if match is found then rename the mac using scutil script

# Room: T9

if [[ "$SERIAL" == "<** ONE OF YOUR MAC SERIALS **>" ]]; then  
MATCH="Y"
NEW_NAME="<*** NAME OF WHAT YOU WANT THIS MAC TO BE CALLED ***>
echo "This mac matches a mac in the list!" 
else 
echo "Not this one!" 
fi

 

 

 

# 3 - Rename Mac using below script if a match is found


if [[ "$MATCH" == "Y" ]]; then
echo $NEW_NAME
scutil --set ComputerName "$NEW_NAME"
scutil --set HostName "$NEW_NAME"
scutil --set LocalHostName "$NEW_NAME"
# Flush DNS cache (optional)
dscacheutil -flushcache
echo "We are renaming this mac now."
else
    echo "This mac didn't match any assetted serial numbers"
fi
 

 

"

 

Hope this helps people and perhaps just restart the mac as a box ticking task!

 

 

Edited by MatTheTech

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...