$apiKey = 'yourApiKeyHere'
$orgID = "yourorIdHere"
$changefrom = "high"
$changeto = "low"
$headers = @{ "Authorization" = "Bearer $apiKey" }
$uri = "https://console.automox.com/api/policies?o=$clientID"
$responses = (Invoke-WebRequest -Method Get -Uri $uri -Headers $headers).Content | ConvertFrom-Json
$ids = $responses | ? {$_.name -match "Windows Policy"} | Select -ExpandProperty id
$middle = '?o='
$ids | % {
$PolicyID = $_
$headers = @{ "Authorization" = "Bearer $apiKey" }
$url = "https://console.automox.com/api/policies/$policyID$middle$orgID"
$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$policyfinal = $response.replace("$changefrom","$changeto")
$body = @"
$policyfinal
"@
$headers = @{
"Authorization" = "Bearer $apiKey"
"Content-Type" = "application/json"
}
$url = "https://console.automox.com/api/policies/$policyID$middle$orgID"
Invoke-WebRequest -Method Put -Uri $url -Headers $headers -Body $body
}
This iterates through any policy that has a name that includes “Windows Policy” and will update the priority of the policy updates from “high” to “low”. While this is a very specific niche use-case, the overall code/script itself can easily be modified to update any other part of a policy through the API.