Category filter
Script to fetch the Apple IDs of users on Mac
Permitting Apple ID usage on the managed devices enables users to sign in to the device or access Apple services, including iCloud, Find My, etc. However, while allowing Apple ID usage, the admin would also like to determine how the users work with Apple IDs and associated services on the devices. For instance, the administrator wants to identify the Apple ID signed in by the user before turning on specific iCloud restrictions. It is helpful when the method is straightforward and can be performed remotely. This doc provides a script that lets you determine if the user has signed in to an Apple ID and, if yes, fetches it. The
Execute Custom Script action from the Hexnode console lets you execute such customized scripts remotely across the devices.
Find if the device uses an Apple ID
The following script checks each user account on the device and determines if they are signed in to an Apple ID. Then, it returns an individual message for each user, either stating that the given user account does not use an Apple ID or specifying the signed-in Apple ID.
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do userHome=$(dscl . read /Users/"$user" NFSHomeDirectory | sed 's/NFSHomeDirectory://' | grep "/" | sed 's/^[ \t]*//') appleid=$(dscl . readpl "${userHome}" dsAttrTypeNative:LinkedIdentity appleid.apple.com:linked\ identities:0:full\ name 2> /dev/null | awk -F'full name: ' '{print $2}') if [[ "${appleid}" == "" ]]; then echo "User:${user} has not signed in with an Apple ID" else echo "User:${user} is signed in with AppleID:${appleid}" fi done |