Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhbush/263531aa2a0920ed597ee9a4664709d0 to your computer and use it in GitHub Desktop.
Save jhbush/263531aa2a0920ed597ee9a4664709d0 to your computer and use it in GitHub Desktop.
update_jamf_pro_user_inventory_using_nomad_credentials.sh
#!/bin/bash
# Original by Rich Trouton
# https://derflounder.wordpress.com/2017/04/12/identifying-which-active-directory-account-is-logged-into-enterprise-connect/
#
# This script is designed to do the following:
#
# 1. Identify if NoMAD is installed on a particular Mac
# 2. If NoMAD is installed, identify the username of the Active Directory account logged into NoMAD.
# 3. Upload the username information to a Jamf Pro server and update the 'User and Location' section
# of the computer's inventory listing.
#
# Identify the username of the logged-in user
logged_in_user=`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 + "\n");'`
# Identify location of the logged-in user's home directory
user_home_location=`/usr/bin/dscl . -read /Users/"${logged_in_user}" NFSHomeDirectory 2>/dev/null | /usr/bin/sed 's/^[^\/]*//g'`
CheckBinary (){
# Identify location of jamf binary.
jamf_binary=`/usr/bin/which jamf`
if [[ "$jamf_binary" == "" ]] && [[ -x "/usr/sbin/jamf" ]] && [[ ! -x "/usr/local/bin/jamf" ]]; then
jamf_binary="/usr/sbin/jamf"
elif [[ "$jamf_binary" == "" ]] && [[ ! -x "/usr/sbin/jamf" ]] && [[ -x "/usr/local/bin/jamf" ]]; then
jamf_binary="/usr/local/bin/jamf"
elif [[ "$jamf_binary" == "" ]] && [[ -x "/usr/sbin/jamf" ]] && [[ -x "/usr/local/bin/jamf" ]]; then
jamf_binary="/usr/local/bin/jamf"
fi
}
# Read logged-in user's login keychain for the username
# used to log into NoMAD
if [[ -d "/Applications/NoMAD.app" ]]; then
/usr/bin/security find-generic-password -l "NoMAD" "${user_home_location}"/Library/Keychains/login.keychain > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
nomad_user=$(/usr/bin/security find-generic-password -l "NoMAD" "${user_home_location}"/Library/Keychains/login.keychain | awk -F "=" '/acct/ {print $2}' | tr -d "\"" | cut -f1 -d"@")
if [[ ! -z "${nomad_user}" ]]; then
CheckBinary
# Update computer's inventory listing in Jamf Pro with logged-in user information
$jamf_binary recon -endUsername $nomad_user
#echo $nomad_user
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment