Noah Talerman
Noah Talerman
In Fleet you can run MDM commands to take action on your macOS, iOS, iPadOS, and Windows hosts, like restarting the host, remotely.
You can run custom commands and view a specific command's results using the fleetctl
command-line interface.
To run a custom command, we will do the following steps:
.xml
with the request payloadfleetctl
fleetctl
You can run any command supported by Apple's MDM protocol or Microsoft's MDM protocol.
The lock and wipe commands are only available in Fleet Premium
For example, to restart a macOS host, we'll use the "Restart a Device" command documented by Apple here.
First, we'll need to create a restart-device.xml
file locally with this payload:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Command</key>
<dict>
<key>RequestType</key>
<string>RestartDevice</string>
</dict>
</dict>
</plist>
To restart a Windows host, we'll use the "Reboot" command documented by Microsoft here.
The restart-device.xml
file will have this payload instead:
<Exec>
<Item>
<Target>
<LocURI>./Device/Vendor/MSFT/Reboot/RebootNow</LocURI>
</Target>
<Meta>
<Format xmlns="syncml:metinf">null</Format>
<Type>text/plain</Type>
</Meta>
<Data></Data>
</Item>
</Exec>
To run a command, we need to specify a target host by hostname.
fleetctl get hosts --mdm
command to get a list of hosts that are enrolled to Fleet and have MDM turned on.fleetctl mdm run-command --payload=restart-device.xml --hosts=hostname
command.Replace the --payload and --hosts flags with your XML file and hostname respectively.
fleetctl get mdm-command-results --id=<insert-command-id>
You can view a list of the 1,000 latest commands:
fleetctl get mdm-commands
The command ID can be used to view command results as documented in step 4 of the previous section.