auto-populating Full Name without LDAP

smithdr
New Contributor III

Hi All,

My company does not currently have an LDAP solution in place, but in the meantime I would like to implement a way for the user's full name from the local account to be automatically populated into the JSS Full Name or Real Name section of the computer profile.

I've been scouring other threads, but I haven't found a definitive answer to what I'm looking for. The closest I've gotten so far is adding the local account username into the JSS.

Thanks for all the help!

2 ACCEPTED SOLUTIONS

stevevalle
Contributor III

You are able to do this with a script. I haven't tested the below, but in theory it should work!

#!/bin/sh

# Get the Full Name of the logged in user
fullName=$(dscl . read /Users/`whoami` RealName | grep -v RealName | cut -c 2-)

# Add the users full name to the computer record in the JSS
jamf recon -realname $fullName

exit 0

Hope this helps or points you in the right direction :)

View solution in original post

smithdr
New Contributor III

Steve, Thank you! This almost get's me there. If I run this script off my user it works correctly, however being run through the JSS it responds with the full name being "System". I assume it's because the script is being run as root. I attempted to sub out the 'whoami; to be $loggedinuser, but I get a strange return.

Really appreciate you jumping in and helping out!

Edit:

So I actually got a little closer - I combined a couple other ideas from different threads and it looks like this now:

#!/bin/sh

#Discover last logged in username
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`

# Get the Full Name of the last logged in user
fullName=$(dscl . read /Users/$lastUser RealName | grep -v RealName | cut -c 2-)

# Add the users full name to the computer record in the JSS
jamf recon -realname "$fullName"

exit 0

When I run this locally I get the complete username back, but when I run it through the JSS I get just the first name returned. I'm sure this part is a quick fix.

Nevermind, Adding quotes to "$fullName" above fixed that issue I was seeing.

View solution in original post

4 REPLIES 4

stevevalle
Contributor III

You are able to do this with a script. I haven't tested the below, but in theory it should work!

#!/bin/sh

# Get the Full Name of the logged in user
fullName=$(dscl . read /Users/`whoami` RealName | grep -v RealName | cut -c 2-)

# Add the users full name to the computer record in the JSS
jamf recon -realname $fullName

exit 0

Hope this helps or points you in the right direction :)

smithdr
New Contributor III

Steve, Thank you! This almost get's me there. If I run this script off my user it works correctly, however being run through the JSS it responds with the full name being "System". I assume it's because the script is being run as root. I attempted to sub out the 'whoami; to be $loggedinuser, but I get a strange return.

Really appreciate you jumping in and helping out!

Edit:

So I actually got a little closer - I combined a couple other ideas from different threads and it looks like this now:

#!/bin/sh

#Discover last logged in username
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`

# Get the Full Name of the last logged in user
fullName=$(dscl . read /Users/$lastUser RealName | grep -v RealName | cut -c 2-)

# Add the users full name to the computer record in the JSS
jamf recon -realname "$fullName"

exit 0

When I run this locally I get the complete username back, but when I run it through the JSS I get just the first name returned. I'm sure this part is a quick fix.

Nevermind, Adding quotes to "$fullName" above fixed that issue I was seeing.

chris_glaske
New Contributor

Hi there! I am attempting to use this script to do the exact same thing and it is returning just a blank result.

Any advice would be super helpful!

Cheers.

Malcolm
Contributor II

This issue was very frustrating, but I eventually hacked a way of doing it via the use of the mdm api the below script is for the username, but a similar code could be used to collect the full name
@chris.glaske @smithdr @stevevalle

create a mdm local user with read rights to the api

and substitute the following in bold, usign the api account for the process, it's not the cleanest way to convert the response, but it does the job. and replace the word username with 'full name' to collect the assigned user full name

strmacbookserial=ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'|tr -d '"'

strassigneduser=/usr/bin/curl -s -u "apiassigneduser":"apiassigneduserpassword" -X GET "https://mdmaddress:8443/JSSResource/computers/match/$strmacbookserial" -H "accept: application/xml" | awk -F'><' '{$1=$1}1' OFS=' ' | grep username | sed -e 's/username>//g' | sed -e 's.</username..g'
echo "strassigneduser $strassigneduser"