Probably a dumb question, but sanity check here – we are substituting all the bracketed strings for actual values, right?
yes, if I do other command type such as “InstallAllUpdates” its coming back fine.
I was able to replicate your issue, getting a (400) bad request when attempting to use policy_{policy_id}_remediate as the docs state. GetOS returns a correct query, so something syntax related must be amiss in the docs. However, as a workaround, there is another query to accomplish your goal using https://developer.automox.com/openapi/axconsole/operation/executePolicy/
Here is a script that I use in our environment from @Tony
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…
thank you so much Matt, that works!
This post gave me some hope till I tried the alternative. 400 bad request still. Note that I am able to lookup the server id, policy id, and org id using my API key so I know there is no issue with the headers or other URIs. I’ve tried getos too which does work.
PS C:\WINDOWS\system32> $FullURI
https://console.automox.com/api/policies/170420/action?o=12345&action=remediateServer&serverID=1093887
PS C:\WINDOWS\system32> $headers = @{
"Authorization" = "Bearer $key"
}
Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:4 char:1
+ Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers
For completeness, here is the original command starting with the server rather than policy.
PS C:\WINDOWS\system32> $EndPoint | select display_name,id,@{n="policyname";e={$_.policy_status.policy_name}},@{n="policyid";e={$_.policy_status.policy_id}},@{n="policytype";e={$_.policy_status.policy_type_name}}
display_name : CHMPTESTVM01
id : 1093887
policyname : Off Domain Patch All
policyid : 170420
policytype : patch
PS C:\WINDOWS\system32> $FullURI
https://console.automox.com/api/servers/1093887/queues?o=12345
PS C:\WINDOWS\system32> $headers
Name Value
---- -----
Content-Type application/json
Authorization Bearer 11111111-1111-1111-1111-111111111111
PS C:\WINDOWS\system32> $RequestBody
{
"command_type_name": "policy_170420_remediate"
}
PS C:\WINDOWS\system32> Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers -Body $RequestBody
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
I got this to work by modifying a script provided by the new purchase success team.
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apiKey")
$FullURI = "https://console.automox.com/api/policies/$($policy.policy_id)/action?o=$orgID&action=remediateServer&serverId=$($ServerID)"
Invoke-RestMethod -Uri $FullURI -Method Post -Headers $headers