Skip to content

Instantly share code, notes, and snippets.

@manicmachine
Created July 10, 2026 00:54
Show Gist options
  • Select an option

  • Save manicmachine/7c009e7f8f38b74acfdced1ca7114821 to your computer and use it in GitHub Desktop.

Select an option

Save manicmachine/7c009e7f8f38b74acfdced1ca7114821 to your computer and use it in GitHub Desktop.
Jamf Pro EA: LAPS Broken
#!/bin/bash
sync_metadata_path="/Library/laps_sync_metadata.json"
jamf_out=$(/usr/local/bin/jamf rotateManagementAccountPassword -verbose 2>&1)
result=""
# Create metadata file
if [[ ! -f "$sync_metadata_path" ]]; then
/usr/bin/touch "$sync_metadata_path"
/bin/chmod 600 "$sync_metadata_path"
fi
# Extract most recent metadata
most_recent_entry=$(/usr/bin/jq '.[0]' "$sync_metadata_path")
most_recent_status=$(echo "$most_recent_entry" | /usr/bin/jq '.status' | /usr/bin/sed 's/\"//g')
most_recent_date=$(echo "$most_recent_entry" | /usr/bin/jq '.date' | /usr/bin/sed 's/\"//g')
date=$(/bin/date)
current_status=""
current_reason=""
# Determine current sync status
# If metadata exists AND the last status is the same as our current status, set date to the last metadata date
if echo "$jamf_out" | /usr/bin/grep -qi "operation was denied"; then
current_status="broken"
current_reason="$jamf_out"
if [[ ! -z "$most_recent_entry" && "$most_recent_status" == "$current_status" ]]; then
date="$most_recent_date"
fi
else
current_status="synced"
fi
# Write metadata when status changes
if [[ -z "$most_recent_entry" ]]; then
/usr/bin/jq --null-input --arg date "$date" --arg status "$current_status" --arg reason "$current_reason" '[{"date": $date, "status": $status, "reason": $reason}]' > "$sync_metadata_path"
elif [[ "$most_recent_status" != "$current_status" ]]; then
/usr/bin/jq --arg date "$date" --arg status "$current_status" --arg reason "$current_reason" '[{"date": $date, "status": $status, "reason": $reason}] + .' "$sync_metadata_path"
fi
if [[ "$current_status" == "broken" ]]; then
result="Broken: $date"
else
result="Synced"
fi
echo "<result>$result</result>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment