Looking for suggestions pulling LDAP Fields to name a computer

MBlank
Contributor

Does anyone know a way to either pull just the first name or username field from a Jumpcloud instance into Jamf?

 

Jamf seems to be able to query userid, username email address and Fullname however I'm looking to try and modify the below script to pull just the first name or username and add it so the computer name will end up being:

XXXX-MBP-FirstName or username-SERIAL Number

 My ideal preference would be to just pull the first name but that's not a stand alone field so I don't think it's possible to pull this info. See sample script below. This would run right after pre-stage which is currently set to not create a username other than admin. Has anyone had success doing this?

----

 

#!/bin/bash


# Get the logged in username
logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name 😕 && ! /loginwindow/ {print $3}')

#get computer serial number
serialNumber=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'`

# Create a string
comp_name="XXXX-MBP-${logged_in_user}-$serialNumber"

# Rename the Mac using the jamf command line tool
jamf SetComputername -name "$comp_name"

jamf recon

exit 0

2 REPLIES 2

bwoods
Valued Contributor

I do something similar to populate the LDAP field in Jamf. I don't think there is a way to grep the first name though. Have you tested your script yet? Looks like it would work from what I can see. 

MBlank
Contributor

The script works. Now I'm just trying to figure out if there's a way to pull the first name of the computer user defined in NAME when setting up the machine.