PreStage Mobile Device Names using User and Location Variables

New Contributor II


Has anyone had any luck with naming Mobile Devices based on variables from the User and Locations fields like Username, Email Address or Full Name even? We require the DEP process to authenticate via LDAP, so these fields are known upon the device enrollment and it would be useful to be able to use these fields from AD in the device names. I know the answer is most likely, but this would be a great feature for Jamf to add into Jamf Pro. Pretty please. 🙂


New Contributor II

*I know the answer is most likely not*

New Contributor III

I can't remember exactly, but I think my District used to do this in the past. In the prestage > Mobile Device name I think you may be able to enter Payload Variables. Here are list of all of them


This may require testing, but essentially in the name field you would put something like "$USERNAME". However we no longer do this, so I think it may have gotten broken in the past...Maybe instead of $USERNAME you would pass "%Username%" instead. Let me know how this works out for you!

Here is some more documentation on Mobile Device Prestages


It says "Note: Using Inventory Preload or authentication during enrollment can automatically populate this information for devices." So I am assuming this still works!

New Contributor II

Thanks for the reply Andrew. I haven't got it to work yet. What Naming Method did you use in the PreStage with the variable $USERNAME or %UserName%.

New Contributor III

We used "Stu-$FULLNAME" so we know the device is a student iPad and who they belong to. We first have them authenticate with LDAP

New Contributor II

Were you using the "Single Name" option for the "Naming Method"? Every time we try that we literally get the iPad named as $FULLNAME instead of the actual full name of the user. 

Are you using Jamf Pro or Jamf School? We are using Pro.

New Contributor III

Hm, I guess this is the reason we moved away from it. I think if it is able to get the User & Location before the name is set it takes it.


We moved to more of an API approach to it:

•Create a smart group with last enrollment of x amount of days

•API call to read through each device in the smart group

•Loops through each device in the smart group

  •Read and store the User & Location info (We create a variable to store the username field)

  •Update the device name (plug in the variable before)

•Goes onto the next device.

New Contributor II

Thanks again Andrew. We have a similar smart group already set up for devices enrolled in the last 24 hours. Would you be willing to share your API script with us?

New Contributor III

It's not the prettiest or the fastest, but I'm a Jamf administrator, not a programmer and it gets the job done! I've gone back and added some comments so you can see what exactly the script is doing. I have a launchdaemon that goes off every week on one of our mini's that we use for caching and it gets the job done!


Note: I never minded it, buuuuut when you run this there are two extra IDs in the beginning it takes. So whatever mobile device has the same ID as your smart group, will be getting its name changed every week. It also will be fetching your site IDs, so the same rule applies for that, but since it is just changing the name of the device and nothing serious...It doesn't hurt anything! If you have any questions let me know!




#Jamf Username
#Jamf Password
#ID of the Smart group (You can find this in the URL when you are viewing the smart group Name/Criteria page)
#You may add a prefix here for the name if you wish. Leave it blank to not add a Prefix

#Gets IDs of Mobile Devices
report=$(curl -sku $username:$password -H "accept: text/xml" "$jamfURL/JSSResource/mobiledevicegroups/id/$smartGroupID" | xmllint --format - | awk -F '[<>]' '/<id>/{print $3}')

#Outputs the IDs to a file
echo "$report" > /Users/shared/IDs.txt

#Reads file IDs then makes it into a csv
sed '$!s/$/,/' /Users/shared/IDs.txt > /Users/shared/IDscomma.csv

#Loops Through Mobile Device IDs and sets name based off of the username
while IFS=, read -r ID; do 
	echo "$ID"
	getUsername=$(curl -sku $username:$password -H "accept: text/xml" "$jamfURL/JSSResource/mobiledevices/id/$ID" | xmllint --xpath 'mobile_device/location/username/text()' -)
	curl -sku $username:$password -H "content-type: text/xml" "$jamfURL/JSSResource/mobiledevices/id/$ID" -X PUT -d "<mobile_device><general><display_name>$prefix$getUsername</display_name></general></mobile_device>"
	curl -sku $username:$password -H "content-type: text/xml" "$jamfURL/JSSResource/mobiledevices/id/$ID" -X PUT -d "<mobile_device><general><device_name>$prefix$getUsername</device_name></general></mobile_device>"
done < /Users/shared/IDscomma.csv




New Contributor II

Thanks again Andrew! We'll give it a try.

Contributor III

Once all of our new devices are enrolled (we authenticate with LDAP) we export the data, concatenate a few fields and then upload with the MUT to name our devices.