Question
Answer (31)
When in association with Apple Configurator 2, devices that erase or Return to Service loop as the device sees a new plug-in and a pending erase command is sent up to the device record after the initial wipe. Create a task that can be run prior to the erase that verifies if the device is managed. If it is managed, proceed with the wipe. The wipe causes the record to be marked as unmanaged and after reboot when a "plug-in" is detected, the check sees the device is not enrolled and will not issue a wipe
Answer:
To create a "Is managed check" that verifies if an Apple device is managed before initiating a wipe or erase command using Apple Configurator 2, follow the steps below:
-
Create a new script: In Apple Configurator 2, go to the
Librarytab and click onNew Script. Name the script, for example,CheckDeviceManagementStatus.scp. -
Add the following script code:
#!/bin/sh
# Get the device's management status using the system_profiler command
management_status=$(system_profiler SCDynamicStore -xml | grep -E '(<key>Management[[:space:]]+:</key>.*<string>[[:space:]]+Managed)</string>' | sed 's/<[^>]*>//g')
# Verify if the device is managed
if [[ "$management_status" == "Managed" ]]; then
echo "Device is managed."
# Proceed with the wipe or erase command
# Replace <your_erase_command> with the actual erase command
# For example: /usr/sbin/dpkg-reconfigure -plow dhcp3-client
#/usr/sbin/<your_erase_command>
else
echo "Device is not managed."
# Display an error message and exit the script
echo "Error: Device is not managed. Aborting wipe/erase command."
osascript -e 'display notification "Device is not managed. Aborting wipe/erase command." with title "Error"'
exit 1
fi
Replace <your_erase_command> with the actual erase command you intend to use.
-
Save and close the script: After adding the script code, save the script and close the script editor.
-
Create a new action: Go to the
Actionstab and click onNew Action. Name the action, for example,CheckDeviceManagementStatusAndWipe. Add the new script as a step in the action. -
Configure the action: Configure the action to run before the wipe or erase command. For example, if you are using the
Automatedtab to manage devices, you can add the action to thePreparephase. -
Save and apply the configuration: Save the configuration and apply it to the devices you want to enforce managed status before wiping or erasing.
With this setup, the "Is managed check" task will run prior to the erase or wipe command, and if the device is managed, it will proceed with the command. If the device is not managed, the check will display an error message and abort the wipe or erase command.