Posted on 12-03-2019 06:41 AM
Is this possible?
We would like to grab the LDAP username assigned in the JSS and the Model and set that as the computers sharing name
User - John Smith
Model - MacBook Pro (2015)
Sharing Name - JohnSmith-MacBookPro(2015)
Does this make sense and is it possible?
Posted on 12-03-2019 08:02 AM
It's possible to get the username or full name (if available) that's assigned to a Mac in the JSS using an API call. Getting the model name is also possible using some scripted methods.
However, I would be hesitant to name the computer with open and close parens like in your example. It might make more sense to use the model identifier, such as MacBookPro15,1
or something like that instead.
Also, have you considered using the LDAP short name instead of the full name for use in naming? I only ask because, just using your example, there could easily be more than one "John Smith" in your org if it's of sufficient size. Although it might be a small risk, it's still a possibility that you could have a name clash if there's 2 John Smith's with MacBook Pro's of the same type.
I assume that each "John Smith" would have a unique LDAP name, even if their actual names are identical, so it might make more sense to use that instead.
Posted on 12-03-2019 08:30 AM
It's possible to get the username or full name (if available) that's assigned to a Mac in the JSS using an API call. Getting the model name is also possible using some scripted methods. However, I would be hesitant to name the computer with open and close parens like in your example. It might make more sense to use the model identifier, such as MacBookPro15,1 or something like that instead. Also, have you considered using the LDAP short name instead of the full name for use in naming? I only ask because, just using your example, there could easily be more than one "John Smith" in your org if it's of sufficient size. Although it might be a small risk, it's still a possibility that you could have a name clash if there's 2 John Smith's with MacBook Pro's of the same type. I assume that each "John Smith" would have a unique LDAP name, even if their actual names are identical, so it might make more sense to use that instead.
Thanks mm2270
It is nice to know that it is possible.
Scripting is not my strong point to be honest, but I will ask around and see if anyone has a good starting point
LDAP short name and model identifier would work for us also
Thanks again for the reply
Posted on 12-03-2019 08:43 AM
Here's an example of how to get these attributes. When the script is run, you will need to supply a Jamf username and password in the parameter 4 and parameter 5 fields, respectively. This avoids needing to hardcode those credentials into the script. The account needs at least Read privileges to computer objects for it to work.
#!/bin/bash
API_USER="$4"
API_PASS="$5"
## Get the JSS URL the Mac is enrolled to. Remove the trailing / character
JSS_URL=$(/usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed 's//$//')
## Pull data using ioreg
DATA=$(/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice)
## Extract the UUID and model strings from the above data
UUID=$(awk -F" '/IOPlatformUUID/{print $4}' <<< "$DATA")
MODEL=$(awk -F" '/model/{print $4}' <<< "$DATA")
## API call to get the username assigned to the Mac
USERNAME=$(/usr/bin/curl -H "Accept: application/xml" -su "${API_USER}:${API_PASS}" "${JSS_URL}/JSSResource/computers/udid/${UUID}/subset/Location" | xpath '/computer/location/username/text()')
echo "Username found: $USERNAME"
echo "Model name found: $MODEL"
## Would be a good idea to put some logic here to make sure both values were properly pulled before trying to name the computer
echo "Computer name will be: ${USERNAME}-${MODEL}"
## Do something here to name the computer, such as `/usr/local/bin/jamf setComputerName -name ${USERNAME}-${MODEL}`
Posted on 12-03-2019 09:14 AM
Thank you!!
So grateful for such an amazing framework
Really appreciated