Script to update User Name and Full Name

Ashour
New Contributor

Hello all,

I created the script below to update the username in the Inventory fields, however I need another line to update the Full Name section. Is there a way I can do it?

!/bin/bash

loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')

Set in JAMF Binary

/usr/local/bin/jamf recon -endUsername $loggedInUser

Thank you.

5 REPLIES 5

JustDeWon
Contributor III

@ashi1986 You would need to make sure your LDAP server is configured, and also make sure you have "Collect user and location from LDAP" enabled in order for this to work properly. That setting can be found in Jamf under Settings>Computer Management>Inventory Collection

jhuls
Contributor III

Previously I was hoping to some day tie Jamf into our inventory system to provide data for our office systems into the User and Location category in Jamf. Currently that data can be filled if the user signs in when building the system as signing is required as part of our dep process. The bad thing is that this is always a tech so the tech's name that builds a system gets listed for each one and then someone has to clean it back out if they remember. There might be a better way to deal with this but I haven't had time to look into it.

I noticed your script and it intrigued me so I played around with it and found something interesting. I only had to run your script as is.

This then seems to automatically fill the other info from AD(LDAP?). I'm not sure if it's supposed to work this way but this looks like a good way to automatically correct all of those systems that haven't been fixed from techs signing in as I described. There are few fields that don't get filled but for me the important ones are. I do apologize that I'm probably not providing much in the way of help for your request but thought I'd thank you for posting this as it spurred some thought on it and it only took a couple min to implement something that will save much more time.

Ideally the info should come from our inventory system because that's where we assign equipment to people but this is a decent enough hack to make it work with our configuration.

MacJunior
Contributor

@JustDeWon  how can I grab username & fullname from LDAP? 

Once you enable "Collect user and location from LDAP".. You can have a policy to run this script below.. Just note this information is pulling from LDAP that you have configured in Jamf already

#!/bin/sh

#Set the log path
logpath="/path/to/logfolder/"

#Ensure logFile can be written
if [ ! -d "${logpath}" ]; then
mkdir "${logpath}"
fi

##Create the logFile
logFile="${logpath}"reconUser.log

# Get the logged in users username
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}')

echo $(date) "Running recon for $currentUser" >> $logFile
echo $(date) "Running recon for $currentUser"

# Run recon, submitting the users username which as of 8.61+ can then perform an LDAP lookup
jamf recon -endUsername $currentUser

echo $(date) "Finished recon for $currentUser" >> $logFile
echo $(date) "Finished recon for $currentUser"

MacJunior
Contributor

Cool, will give it a shot .. many thanks