Retrieve Policy List and Schedules Using PowerShell
Use a PowerShell script to retrieve a list of all policies and schedules for your organization and put them in an Excel spreadsheet.
There are two areas in the code that you’ll need to update to get the script to function:
-
$orgID = 'YOUR_ORG_ID'
You will need your Org ID, which can be found by looking at the URL. Select the value after the
?o=
-
$apiKey = 'YOUR_API_KEY'
In your console, go to Settings → Secrets & Keys and select the API key.
Note: The API key is per user. Each user will have a unique set of API keys.
Policy List and Schedules Script
Use this script to retrieve a list of all your policies in your organization and put them in an Excel spreadsheet.
See also Scheduling Examples and Trailing Zeros description.
# 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
Scheduling Examples and Trailing Zeros
Example days per weekFor 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.
Every Day : Mon/Wed/Fri only : |
Example weeks per monthWeeks 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.
Every Week: 2nd/4th weeks only: |
Example months per yearMonths continue the trend with 12 digits with a trailing zero. Starting with December and ending with January.
Every Month: Mar/Jun/Sep/Dec = |
Related Topics
Community: Get A List Of All Policies For Your Organization and Their Schedules