Skip to main content
Question

Populate JSS Computer Name via LDAP Attributes


Forum|alt.badge.img+8

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?

4 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • December 3, 2019

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.


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 49 replies
  • December 3, 2019
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


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • December 3, 2019

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}`

Forum|alt.badge.img+8
  • Author
  • Contributor
  • 49 replies
  • December 3, 2019

Thank you!!

So grateful for such an amazing framework
Really appreciated


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings