This script collects Configuration Profiles (if present) to /users?shared csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |