script to rename devices

danlaw777
Contributor III

Has anyone made a script or profile to rename devices in jamf pro? right now, there is onl;y 1 option (within pre-stage enrollment) and i'd like to have a 2nd. my goal it to name the phones using a prefix of P followed by the serial, and a prefix of a T for the ipads. 

 

anyone doing something like this?

4 REPLIES 4

bcbackes
Contributor III

I don't manage iOS devices in Jamf, just Macs but here's what I'm using for renaming Macs by adding a prefix of "M-" before the serial number. Maybe it will help lead you in the right direction? 

#!/bin/sh

prefix="M-"
serial=`system_profiler SPHardwareDataType | awk '/Serial Number/ { print $4 }'`

sudo /usr/sbin/scutil --set ComputerName "${prefix}${serial}"
sudo /usr/sbin/scutil --set HostName "${prefix}${serial}"
sudo /usr/sbin/scutil --set LocalHostName "${prefix}${serial}"

sleep 5

exit 0

 

Hello, how could this script be modified to use M- but only the last 7 characters of the serial number?

Matt
Valued Contributor

Grep the serial number.

This script should do what you asking for

#!/bin/sh

SerNum=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
lastSeven="${SerNum: -7}"

jamf setComputerName --name $lastSeven -prefix "M-"