List All macOS Configuration Profile information to a csv file

This script collects Configuration Profiles (if present) to /users?shared csv file

#!/bin/bash
# This script collects Configuration Profiles (if present) to /users?shared csv file
# Define the output file with current date, time, and hostname
currentDateTime=$(date "+%Y-%m-%d_%H-%M-%S")
hostname=$(hostname)
outputFile="/Users/shared/${currentDateTime}_config_profiles_${hostname}.csv"
# Use the profiles command to get configuration profiles in XML format
profilesData=$(profiles show -output stdout-xml)
# Check if profiles are present
if echo "$profilesData" | grep -q '<array>'; then
# Profiles are present, process the data
echo "$profilesData" | awk -F'<string>|</string>' '
BEGIN {
print "ProfileDisplayName,ProfileIdentifier,ProfileUUID" > "'"$outputFile"'"
}
/<key>PayloadDisplayName<\/key>/ { getline; displayName = $2 }
/<key>PayloadIdentifier<\/key>/ { getline; identifier = $2 }
/<key>PayloadUUID<\/key>/ { getline; uuid = $2; print displayName "," identifier "," uuid > "'"$outputFile"'" }
'
echo "Profile data saved to $outputFile"
else
# No profiles are present
echo "No configuration profiles found."
fi

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *