Posted on 02-25-2022 04:11 AM
Hello,
1) We want to name our Macbooks based on below criteria:
2) We want as well to rename already enrolled computers using same criteria:
We intend to apply this naming convention on:
Jamf Pro looks limited in this context.
Any ideas ?
Solved! Go to Solution.
Posted on 03-01-2022 05:49 AM
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
04-06-2022 06:14 AM - edited 04-06-2022 06:17 AM
Hi @marcelp
I rather edit the script as shown. This works just fine. Thanks so much for you valuable help.
Warmest regards,
Posted on 02-25-2022 04:46 AM
Hello @Jannifer2021
Nice to meet you. Any Idea about my request ?
02-25-2022 06:01 AM - edited 02-25-2022 06:03 AM
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.
Posted on 02-25-2022 06:34 AM
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 :’)"
02-25-2022 06:46 AM - edited 02-25-2022 06:47 AM
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-"
Posted on 02-25-2022 06:49 AM
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.
Posted on 02-25-2022 12:50 PM
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.
Posted on 03-01-2022 01:46 AM
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?
Posted on 03-01-2022 05:44 AM
Issue is my hostname changed to PREFIX00000 looks like something is missing with:
id=$(awk -F'<computer_id>|</computer_id>' '{print $2}' <<< "$getinfo" | xargs)
Posted on 03-01-2022 05:49 AM
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
Posted on 03-28-2022 04:43 AM
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
Posted on 03-28-2022 11:45 PM
I would make a smart group with:
Computer Name like prefix
And scope the policy with it. That way it reruns if it fails.
04-06-2022 06:14 AM - edited 04-06-2022 06:17 AM
Hi @marcelp
I rather edit the script as shown. This works just fine. Thanks so much for you valuable help.
Warmest regards,
Posted on 04-23-2024 01:53 PM
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
}
Posted on 05-07-2024 09:56 AM
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!