This script will apply multiple policies from your organization to a system. Say you always apply the same five policies to a newly built system, you could use this to apply those policies with one click to your new system. This will install any policy available in your organization regardless of whether it is attached to the group the system is in or not.
Make sure you’re not attempting to apply a macOS/Linux worklet or required software to a Windows device.
Just set the following:
$apiKey = 'YOUR_API_KEY'
- in your console, go to Settings->API and select the API key. Note that the API key is per admin user, so you and another admin in your console will have different API keys.
$orgID = 'YOUR_ORG_ID' & $serverID = 'YOUR_SERVER_ID'
- put your Org ID & Server ID which can be found by looking at the URL on the device page and selecting the value after the “?s=” & “?o=”: https://console.automox.com/device-detail?s=99999&o=1234]. In this example the Server ID is 99999 and the Org ID is 1234.
$policies
- put your list of PolicyIDs here. For example, $policies = @(11111,22222,33333). The easiest way to find the policy IDs are to go to the page of each policy and grab the value after the “&pid=” : ahttps://console.automox.com/policy-custom-editor?frompage=system-management&pid=99999&o=1234]. In this example the policy ID is 99999.
$apiKey = 'YOUR_API_KEY'
$orgID = 'YOUR_ORG_ID'
$serverID = 'YOUR_SERVER_ID'
$policies = @(PolicyID1,PolicyID2,PolicyID3,PolicyID4,PolicyID5,etc...)
foreach ($policy in $policies) {
$headers = @{ "Authorization" = "Bearer $apiKey" }
$url = "https://console.automox.com/api/policies/$policy/action?o=$orgID&action=remediateServer&serverId=$serverID"
Invoke-WebRequest -Method POST -Uri $url -Headers $headers
}