Skip to main content

Hello,

1) We want to name our Macbooks based on below criteria: 

  • Prefix + 5 digits 00001 --> 99999.
  • No duplicate should be created.
  • Process should be silent or at least automated.

2) We want as well to rename already enrolled computers using same criteria:

  • Prefix + 5 digits 00001 --> 99999.
  • No duplicate should be created.
  • Process should be silent or at least automated.

We intend to apply this naming convention on:

  • Most machines are DEP Enrolled.
  • Some are Self-Initiated

Jamf Pro looks limited in this context.

Any ideas ?

 

Hello @Jannifer2021  

Nice to meet you. Any Idea about my request ? 


How about using Jamf Pro Computer ID as the number?

 

 

getinfo=$(jamf recon)

id=$(awk -F'<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)
digits=$(echo 00000$id | tail -c 6)

jamf setComputerName -name "PREFIX-$digits"
jamf recon #this is only needed for immidiate update in jamf inventory

 

 

 This will be a unique value. It's also useful for administrators as you know the URL for computer object in jamf from hostname.


A unique arbitrary value may be problematic.  For any value that's not tied to a physical attribute of the device (e.g. WiFI or BT MAC address, serial number), there needs to be a source of truth.  If your devices have asset tags, then there should be database (or at the very least a spreadsheet) with a 1:1 correlation of serial number to asset tag.  This could be used to set the device names based on the asset tag value.

 

@marcelp 's solution uses an arbitrary unique value, but has the added advantage that Jamf Pro already knows what that value is without first needing to upload a table of values via the MUT.

 

If the goal is simply a unique name with no PII (i.e. something other than "Escobar's MacBook Air"), you could just use your prefix followed by the WiFi MAC address (this example removes the ":" to clean it up a little):

 

/usr/local/bin/jamf setComputerName -name "Mac-$(ifconfig en0 | awk '/ether/{print $2}' | tr -d :’)"

As others have suggested, the Jamf Pro Computer ID seems logical if you need a number for some reason.

I also like the suggestion of MAC Address, or you could use SerialNumber:

/usr/local/bin/jamf setComputerName -useSerialNumber -prefix "PrefixHere-"

 


As others have suggested, the Jamf Pro Computer ID seems logical if you need a number for some reason.

I also like the suggestion of MAC Address, or you could use SerialNumber:

/usr/local/bin/jamf setComputerName -useSerialNumber -prefix "PrefixHere-"

 


Serial Number has the added benefit that it is persistent through a service event (for macOS devices anyway) where WiFi MAC address will change if the device requires a new logic board.


The only disadvantage I can think of in using the Jamf Computer ID as the numerical source is in the rare case of a device being deleted from Jamf and then re-enrolled. It will get a new ID in Jamf.

However, as long as your computer naming policy re-runs on the re-enrolled Mac (and it should if set up correctly), it will use the new ID and rename the Mac accordingly. Otherwise, using the Jamf ID seems like a pretty good solution to me. It will always be unique in your Jamf instance.


guys, thanks for all details. We are using name convention based on a prefix + 5 digits for all company devices.

Thus, using the computer ID in Jamf should be the best scenario. 

@marcelp I scoped my mac in a policy linked to your script. My hostname is: Prefix00000. What's is missing in order to replace the last zeros by the Jamf computer ID?


Issue is my hostname changed to PREFIX00000 looks like something is missing with:  

id=$(awk -F'<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)


line after id cuts out the digits. You can set your Prefix in the line above

getinfo=$(jamf recon)

PREFIX="YOURPREFIX"
id=$(awk -F'<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)
digits=$(echo 00000$id | tail -c 6)

jamf setComputerName -name "$PREFIX-$digits"
jamf recon #this is only needed for immidiate update in jamf inventory

 


line after id cuts out the digits. You can set your Prefix in the line above

getinfo=$(jamf recon)

PREFIX="YOURPREFIX"
id=$(awk -F'<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)
digits=$(echo 00000$id | tail -c 6)

jamf setComputerName -name "$PREFIX-$digits"
jamf recon #this is only needed for immidiate update in jamf inventory

 


Hi @marcelp 

This works just fine for 90% of our fleet. I have a remark though:

When client have network issue, the script assignt default name to machine locally & jamf: prefex + 00000!

jamf log error:

Can we add a script line to check client network before running ? any suggestion ?

Thanks in advance


I would make a smart group with:

Computer Name like prefix

And scope the policy with it. That way it reruns if it fails.


Hi @marcelp 

I rather edit the script as shown. This works just fine. Thanks so much for you valuable help.

Warmest regards,


I fixed a few things with the script.

I moved the curly bracket ({)about the if statement and added a fi above the last jamf recon command.

This runs cleaner. Your PREFIX choice is your own.

I hope this helps.

#!/bin/bash
{
if (jamf recon) then

getinfo=$(jamf recon)

PREFIX="MBP-"
id=$(awk -F '<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)
digits=$(echo 00000$id | tail -c 6)

jamf setComputerName -name $PREFIX$digits

/usr/sbin/scutil --set HostName $PREFIX$digits
/usr/sbin/scutil --set LocalHostName $PREFIX$digits
/usr/sbin/scutil --set ComputerName $PREFIX$digits
fi

jamf recon #Only needed to initiate immediate update in Jamf Inventory

}


Has anyone seen duplicate names after running this on computers managed by Jamf? 


Question, would there be a way to add a check for the hostname before it is applied?


The reason is our org has had a naming convention for some time and I believe certain names pre-exist due to this. Or maybe I should move away from computerID and use the serial number. 


Thinking out loud here, maybe a different approach to check if a duplicate name exists to rename the computer immediately. 


Anyway, thank you Nation!


 


 


Reply