Posted on 09-26-2016 01:45 PM
Hi, I've found some variations of this elsewhere but nothing that seems to address what I am specifically looking for. Here is what I would like to do.
I have all the AD mappings set up, departments and buildings match exactly what are stored in AD. If I use the look up when adding a user to a machine record in the JSS, all the info populates correctly.
The piece I am missing is, on a newly imaged machine, when the first AD user logs into the machine that user name is used to add that user to the machine in the jss.
Has anyone ever done this?
Posted on 09-26-2016 01:58 PM
$3 is the variable JAMF uses for the AD username after login. We currently use this for external drive mapping.
Posted on 09-26-2016 02:01 PM
For example, we add this as a dock item for shared drive mapping after every login.
smb://cchs-fs1/HOME/$3
Posted on 09-26-2016 02:57 PM
Would something like this help you out?
[https://derflounder.wordpress.com/2011/12/05/auto-populating-the-location-info-in-the-casper-jss-inventory/](link URL)
Posted on 09-26-2016 07:36 PM
I got this from JAMF Support,it works well here, maybe help
currentUser=defaults read /Library/Preferences/com.apple.loginwindow lastUserName
jamf recon -endUsername $currentUser
exit 0
Set the execution frequency to once per computer and in policy scope add local user that IT used to exclusion , this will only get the first AD user. Sorry for my poor english....
Posted on 09-28-2016 09:47 AM
This is our script to achieve this:
#!/bin/bash
#log the output of the script to the jamf.log for easy viewing
logfile=/var/log/jamf.log;
exec >> $logfile 2>&1;
#------------------------------
#-------BEGIN VARIABLES--------
#------------------------------
scriptname="populate_username.sh";
breadcrumb="/Library/BCGS/breadcrumb_username_populated.txt";
currentUser=""
currentUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName` >/dev/null 2>/dev/null
#set LoggedInUser as the current user
if [ `ls -l /dev/console | cut -d " " -f 4` == "root" ]
then
#script is run at login, so the user is the $3 variable
LoggedInUser=$3
else
#script is run as self service, so the user is not sent to the script
LoggedInUser=`ls -l /dev/console | cut -d " " -f 4`
fi
#------------------------------
#-------END VARIABLES----------
#------------------------------
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: ------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: --- Starting $scriptname"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Script variables:"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: $LoggedInUser = $LoggedInUser"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: $currentUser = $currentUser"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:"
if [ -f "$breadcrumb" ]
then
# We should skip running this script, as it looks like it has already run at a previous reboot.
# In theory this should never occur, as it should be exlcuded in the policy, so this is a second
# measure.
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Skipped populating the username as we have already done this."
else
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Username is going to be '$LoggedInUser'."
# Submit an inventory report and include the current user to be written to the
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Running 'jamf recon -endUsername $LoggedInUser."
jamf recon -endUsername $LoggedInUser >/dev/null 2>/dev/null
# Create the breadcrumb so we know not to run the script again
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Creating the breadcrumb."
echo $LoggedInUser >> $breadcrumb
# Run recon again to pick up the breadcrumb extension attribute
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Running jamf recon for a second time."
jamf recon >/dev/null 2>/dev/null
fi
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: --- Finished $scriptname"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: ------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: "
exit 0
Posted on 09-28-2016 10:42 AM
How often / what triggers do you use to run that script? Startup? Login? Everyhour?
Posted on 09-28-2016 06:15 PM
We use breadcrumbs for many things, they're basically just a way we can record if something has happened, sometimes we put data in them.
We then create extension attributes for the breadcrumbs, and smart groups from those extension attributes.
So in this case, the policy runs at login, on a recurring basis, but we exclude computers that have the breadcrumb on them from the scope.