This PR closes https://github.com/fleetdm/fleet/issues/21108 @noahtalerman, I double-checked all redirects, and they are working. Clicking through the URLs in [this spreadsheet](https://docs.google.com/spreadsheets/d/1djVynIMuJK4pT5ziJW12CluVqcaoxxnCLaBO3VXfAt4/edit?usp=sharing) is a pretty quick way to go through them all. Note that "Audit logs" and "Understanding host vitals" redirect to the contributor docs on GitHub, so they will throw a 404 until this is merged. Some new guides benefitted from a name change, so they make more sense as stand-alone guides, and also so that we don't have to mess around with more redirects later. Those name changes followed [this convention](https://fleetdm.com/handbook/company/communications#headings-and-titles), which was recently documented in the handbook. Have fun! --------- Co-authored-by: Eric <eashaw@sailsjs.com> Co-authored-by: Noah Talerman <noahtal@umich.edu>
3.3 KiB
MDM commands
In Fleet you can run MDM commands to take action on your macOS, iOS, iPadOS, and Windows hosts, like restarting the host, remotely.
Custom commands
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:
- Create a
.xmlwith the request payload - Choose a target host
- Run the command using
fleetctl - View our command's results using
fleetctl
Step 1: Create an XML file
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>
Step 2: Choose a target host
To run a command, we need to specify a target host by hostname.
- Run the
fleetctl get hosts --mdmcommand to get a list of hosts that are enrolled to Fleet and have MDM turned on. - Find your target host's hostname. You'll need this hostname to run the command.
Step 3: Run the command
- Run the
fleetctl mdm run-command --payload=restart-device.xml --hosts=hostnamecommand.
Replace the --payload and --hosts flags with your XML file and hostname respectively.
- Look at the on-screen information. In the output you'll see the command to see results.
Step 4: View the command's results
- Run the
fleetctl get mdm-command-results --id=<insert-command-id> - Look at the on-screen information.
List recent commands
You can view a list of the 1,000 latest commands:
- Run
fleetctl get mdm-commands - View the list of latest commands, most recent first, along with the timestamp, targeted hostname, command type, execution status and command ID.
The command ID can be used to view command results as documented in step 4 of the previous section.