-
Notifications
You must be signed in to change notification settings - Fork 7
/
GrabAXAPIData.ps1
236 lines (179 loc) · 7.23 KB
/
GrabAXAPIData.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Update these variables with your API Key, orgID & save directory/filename
# This script expects the C:\temp\ path to already exist and will overwrite an existing file
$apiKey = '<YOUR_KEY_HERE>'
$orgID = '<YOUR_ORG_HERE>'
$page = 0
$limit = 500
$headers = @{"Authorization" = "Bearer $apiKey"}
#############################################################################################################
#HealthReport
$expDir = 'C:\Temp'
$servers = @()
while($true) {
$uri = "https://console.automox.com/api/servers?o=$orgID&api_key=$apiKey&l=$limit&p=$page"
$resp = (Invoke-WebRequest -Method GET -Uri $uri -UseBasicParsing).Content | ConvertFrom-Json | Select-Object results
$OutputVol = $resp.results `
| Select-Object Name, agent_version, needs_reboot, last_disconnect_time, last_refresh_time, pending_patches, patches, `
last_update_time, os_family, os_name, os_version, id, server_group_id, create_time -ExpandProperty detail `
| Where-Object VOLUME -NE $null
$resp = (Invoke-WebRequest -Method GET -Uri $uri -UseBasicParsing).Content | ConvertFrom-Json | Select-Object results
$OutputNoVol = $resp.results `
| Select-Object Name, agent_version, needs_reboot, last_disconnect_time, last_refresh_time, pending_patches, patches, `
last_update_time, os_family, os_name, os_version, id, server_group_id, create_time -ExpandProperty detail `
| Where-Object VOLUME -EQ $null
$Output = $OutputVol `
| Select-Object Name, agent_version, PS_VERSION, AUTO_UPDATE_OPTIONS, WSUS_CONFIG, UPDATE_SOURCE_CHECK, WMI_INTEGRITY_CHECK, needs_reboot, `
last_disconnect_time, last_refresh_time, pending_patches, patches, last_update_time, os_family, os_name, os_version, id, server_group_id, create_time -ExpandProperty VOLUME `
| Select-Object Name, agent_version, PS_VERSION, AUTO_UPDATE_OPTIONS, WSUS_CONFIG, UPDATE_SOURCE_CHECK, WMI_INTEGRITY_CHECK, needs_reboot, `
last_disconnect_time, last_refresh_time, pending_patches, patches, last_update_time, os_family, os_name, os_version, id, server_group_id, create_time, IS_SYSTEM_DISK `
,@{
Name = 'Free (GB)'
Expression = { ($_.FREE/1000000000).ToString("#####.#") }
} | Where-Object IS_SYSTEM_DISK -EQ True | Sort-Object Name
$servers += $Output
$servers += $OutputNoVol
$page += 1
if($resp.results.Count -lt $limit) {
break
}
}
$servers | Export-Csv -Path "$expDir\health.csv" -NoTypeInformation -Force
#####################################
#Get packages
##Reset Variables
$page = 0
$filepath = "$expDir\packages.csv"
while($true) {
$urlPackages = "https://console.automox.com/api/orgs/$orgID/packages?o=$orgID&l=$limit&p=$page"
$response = (Invoke-WebRequest -Method Get -Uri $urlPackages -Headers $headers).Content | ConvertFrom-Json
Write-Output $page
$data += $response
$page += 1
if($response.count -lt $limit) {
break
}
}
$data | Group-Object display_name | Sort-Object name | Select-Object Count,name `
| Export-Csv -Path $filepath -NoTypeInformation
#Get SoftwareInv
$page = 0
$filepath = "$expDir\SoftwareInv.csv"
Set-Content $filepath -Value "Computer,display_name,version"
$apiInstance = 'https://console.automox.com/api/'
$apiTable = 'servers'
$orgAndKey = "?o=$orgID&api_key=$apiKey"
# Put components together
$getURI = $apiInstance + $apiTable + $orgAndKey
# Get the json body of the Web Request
$jsonReturn = (Invoke-WebRequest -UseBasicParsing -Method Get -Uri $getURI).Content
# Convert to object with manipulatable properties/values
$servers = $jsonReturn | ConvertFrom-Json
$servers = $servers | Sort-Object name
# Check each server for software
foreach ($server in $servers) {
$serverID = $server.id
$serverName = $server.name
Write-Output $serverName
$orgAndKey = "/$serverID/packages?o=$orgID"
# Put components together
$getURI = $apiInstance + $apiTable + $orgAndKey
$headers = @{ "Authorization" = "Bearer $apiKey" }
$response = (Invoke-WebRequest -Method Get -Uri $getURI -Headers $headers).Content | ConvertFrom-Json
$response | Where-Object {$_.installed -EQ $true} | Select-Object @{label="Computer"; Expression= {"$serverName"}},Display_Name,Version `
| Sort-Object Display_Name | Export-Csv -Path $filepath -NoTypeInformation -Append -Force
}
##Servers.Endpoints
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/servers?o=$orgID&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating Servers json..."
$data | Out-File "$expDir\Servers.json"
##ServerGroups
Start-Sleep -Seconds 5
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/servergroups?o=$orgID&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating Servergroups json..."
$data | Out-File "$expDir\ServerGroups.json"
##Prepatch Report
Start-Sleep -Seconds 5
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/reports/prepatch?o=$orgID&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating PrePatch json..."
$data | Out-File "$expDir\PrePatch.json"
##PolicyStats
Start-Sleep -Seconds 5
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/policystats?o=$orgID&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating PolicyStats json..."
$data | Out-File "$expDir\PolicyStats.json"
##PackagesWaiting
Start-Sleep -Seconds 5
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/orgs/$orgID/packages?o=$orgID&awaiting=1&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating PackagesWaiting json..."
$data | Out-File "$expDir\PackagesWaiting.json"
##Policies
Start-Sleep -Seconds 5
##Reset Variables
$page = 0
$data = @()
while($true) {
$url = "https://console.automox.com/api/policies?o=$orgID&limit=$limit&page=$page"
$resp = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content
$data += $resp
if($resp.results.count -lt $limit) {
break
}
$page += 1
}
Write-Host "Creating Policys json..."
$data | Out-File "$expDir\Policies.json"