Last active
June 3, 2019 19:43
-
-
Save talkingmoose/aeafdf507d0da7fa62f0a964a7a4cbe5 to your computer and use it in GitHub Desktop.
Reads plain text file list of mobile device serial numbers and sends Disable Lost Mode command to each, one at a time.
This file contains hidden or 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 | |
| # server connection information | |
| URL="https://jamfpro.talkingmoose.net:8443" | |
| userName="api-editor" | |
| password="P@55w0rd" | |
| # path to list of serial numbers | |
| deviceList="/path/to/file.txt" | |
| mobileDeviceList=$( /bin/cat "$deviceList" ) | |
| # send Lost Mode command to every device in mobile device list | |
| for aDevice in ${mobileDeviceList[@]} | |
| do | |
| # get Jamf Pro ID for device | |
| deviceID=$( /usr/bin/curl -s "$URL/JSSResource/mobiledevices/serialnumber/$aDevice" \ | |
| --user "$userName:$password" \ | |
| --header "Accept: text/xml" \ | |
| --request GET | \ | |
| /usr/bin/xpath '/mobile_device/general/id/text()' ) | |
| # API submission command | |
| xmlData="<mobile_device_command> | |
| <general> | |
| <command>DisableLostMode</command> | |
| </general> | |
| <mobile_devices> | |
| <mobile_device> | |
| <id>$deviceID</id> | |
| </mobile_device> | |
| </mobile_devices> | |
| </mobile_device_command>" | |
| # flattened XML | |
| flatXML=$( /usr/bin/xmllint --noblanks - <<< "$xmlData" ) | |
| /usr/bin/curl -s "$URL/JSSResource/mobiledevicecommands/command/DisableLostMode"\ | |
| --user "$userName":"$password" \ | |
| --header "Content-Type: text/xml" \ | |
| --request POST \ | |
| --data "$flatXML" | |
| echo "Sending Disable Lost Mode Command to Device ID: $deviceID..." | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment