Get A List Of All Policies For Your Organization and Their Schedules

  • 4 June 2021
  • 1 reply
  • 270 views

Userlevel 5

This API script will get a list of all of your policies in your organization and put them in an Excel spreadsheet.


NOTE: Due to the way Excel auto-formats, the “schedule months” column may show in scientific notation due to the length. To fix the display of them, highlight the column, right-click on the column, click Format Column, choose Custom, then set the Type to 0.


Just set the following:


$apiKey = 'YOUR_API_KEY' - in your console, click on the three dots in the upper right, select KEYS, then copy your 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' - put your Org ID which can be found by looking at the URL on the device page and selecting the value after the “?o=”: [https://console.automox.com/device-detail?s=99999&o=1234 ]. In this example the Org ID is 1234.



Example days per week :


For scheduling days of the week, there will be 7 digits with a trailing zero to mark the end. This starts on Sunday and ends on Monday. 1 represents ON and 0 represents OFF for each day of the week.


Sun|Sat|Fri|Thu|Wed|Tue|Mon|TrailingZero


Every Day : 11111110


Mon/Wed/Fri only : 00101010



Example weeks per month:


Weeks are scheduled similarly to days, except there are 5 digits with a trailing zero. This starts on the 5th week of the month and ends with the 1st week of the month.


5th|4th|3rd|2nd|1st|TrailingZero


Every Week: 111110


2nd/4th weeks only: 010100



Example months per year:


Months continue the trend with 12 digits with a trailing zero. Starting with December and ending with January.


Dec|Nov|Oct|Sep|Aug|Jul|Jun|May|Apr|Mar|Feb|Jan|TrailingZero


Every Month: 1111111111110


Mar/Jun/Sep/Dec = 1001001001000


# Replace the two variables below with your Org ID and your API key
$orgID = 'YOUR_ORG_ID'
$apiKey = 'YOUR_API_KEY'

# Replace if you'd like the output in another location
$expDir = 'C:\Temp\Policy_Schedules.csv'

# --------------------------------------

$servers = @()
$output = @()
$page = 0
$limit = 500

$headers = @{ "Authorization" = "Bearer $apiKey" }

while($true) {

$url = "https://console.automox.com/api/policies?o=$orgID&l=$limit&p=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json

$output = $resp | Select-Object id, name, policy_type_name, `
@{ Name = 'schedule days'; Expression = { [Convert]::ToString($_.schedule_days,2) }}, `
@{ Name = 'schedule weeks'; Expression = { [Convert]::ToString($_.schedule_weeks_of_month,2) }}, `
@{ Name = 'schedule months'; Expression = { [Convert]::ToString($_.schedule_months,2) }}, `
schedule_time, notes, create_time, server_count

$servers += $Output
$page += 1

if($resp.Count -lt $limit) {
break
}

}

$servers | Export-Csv -Path $expDir -NoTypeInformation -Force

1 reply

Nice! Worked like a charm 👍

Reply