We’ve never fully standardized on having everyone in our org sync their Desktop and Documents folders to their OneDrive, and I’ve been working on getting that done recently. First step: create an extension attribute that shows the OneDrive redirection status on each Mac so I could build some smart groups.
I kept it simple and just had it look to see whether the user’s Desktop and Documents folders were in their default locations, or if they had OneDrive in the file path of their locations. If it’s the former, it displays “Disabled.” If it’s the latter, it displays “Enabled.” If only one of the two folders are synced to OneDrive, it displays “Partial.”
Just wanted to share in case this was useful for anyone else!
#!/bin/bash
# Extension Attribute to check if Desktop and Documents are syncing with OneDrive (KFM)
# Author: John William Sherrod jwsherrod@mac.com
# Version 1.0, Date: 08-28-2025
# Get the currently logged-in user:
loggedInUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')
# Check if a user is logged in:
if i -z "$loggedInUser" ]; then
echo "<result>Error: No logged-in user found</result>"
exit 1
fi
# Get the user's home folder path:
homeFolder="/Users/$loggedInUser"
# Verify the home folder exists:
if o ! -d "$homeFolder" ]; then
echo "<result>Error: Home directory $homeFolder not found for user $loggedInUser</result>"
exit 1
fi
# Expected default locations for Desktop and Documents:
DEFAULT_DESKTOP="$homeFolder/Desktop"
DEFAULT_DOCUMENTS="$homeFolder/Documents"
# Resolve the actual paths of Desktop and Documents (follows symlinks if redirected):
DESKTOP_PATH=$(readlink -f "$homeFolder/Desktop" 2>/dev/null || echo "$DEFAULT_DESKTOP")
DOCUMENTS_PATH=$(readlink -f "$homeFolder/Documents" 2>/dev/null || echo "$DEFAULT_DOCUMENTS")
# Check if paths contain "OneDrive" to indicate KFM redirection:
if r "$DESKTOP_PATH" == *"/OneDrive"* && "$DOCUMENTS_PATH" == *"/OneDrive"* ]]; then
echo "<result>Enabled</result>"
elif re "$DESKTOP_PATH" == *"/OneDrive"* || "$DOCUMENTS_PATH" == *"/OneDrive"* ]]; then
echo "<result>Partial</result>"
else
echo "<result>Disabled</result>"
fi
exit 0