Posted on 10-21-2021 01:51 PM
Hello
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. 🙂
Posted on 10-21-2021 02:03 PM
*I know the answer is most likely not*
Posted on 10-22-2021 07:34 AM
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 https://docs.jamf.com/10.28.0/jamf-pro/administrator-guide/Mobile_Device_Configuration_Profiles.html
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!
Posted on 10-22-2021 07:36 AM
Here is some more documentation on Mobile Device Prestages https://docs.jamf.com/10.33.0/jamf-pro/administrator-guide/Mobile_Device_PreStage_Enrollments.html
It says "Note: Using Inventory Preload or authentication during enrollment can automatically populate this information for devices." So I am assuming this still works!
Posted on 10-22-2021 08:21 AM
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%.
Posted on 10-22-2021 08:32 AM
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
Posted on 10-22-2021 09:11 AM
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.
10-22-2021 09:41 AM - edited 10-22-2021 09:42 AM
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.
Posted on 10-22-2021 10:50 AM
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?
10-22-2021 12:31 PM - edited 10-22-2021 12:34 PM
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!
#!/bin/bash
#Jamf Username
username=""
#Jamf Password
password=""
#Your JAMF URL
jamfURL=""
#ID of the Smart group (You can find this in the URL when you are viewing the smart group Name/Criteria page)
smartGroupID=""
#You may add a prefix here for the name if you wish. Leave it blank to not add a Prefix
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
Posted on 10-22-2021 01:41 PM
Thanks again Andrew! We'll give it a try.
Posted on 10-25-2021 11:13 AM
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.