Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/4c5ffc53ed4aca4d92a81bf83ddea4c9 to your computer and use it in GitHub Desktop.
Save talkingmoose/4c5ffc53ed4aca4d92a81bf83ddea4c9 to your computer and use it in GitHub Desktop.
Reads managed Apple admin account for date and time of last password change and reports in ISO 8601 format.
#!/bin/zsh
# get LAPS account username
lapsUsername=$( /usr/libexec/PlistBuddy -c "Print :Users:0:shortName" /var/db/ConfigurationProfiles/Settings/.setupUser )
# read LAPS account for password information
userPasswordInfo=$( /usr/bin/dscl . read "/Users/$lapsUsername" accountPolicyData | /usr/bin/tail -n +4 )
# extract Unix epoch date from account password information
passwordChangeDateEpoch=$( /usr/bin/xpath -e '//key[text()="passwordLastSetTime"]/following-sibling::real[1]/text()' 2>/dev/null <<< "$userPasswordInfo" )
# convert Unix epoch date to ISO 8601 standard format
passwordChangeDate=$( /bin/date -j -f "%s" "$passwordChangeDateEpoch" +"%F %T" 2>/dev/null )
# report value to Jamf Pro according to computer's local time zone
echo "<result>$passwordChangeDate</result>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment