Hi @randygarland,
You are pretty close with this one!
To output the contents of your API call, you’ll just need to call the $response
variable again. This will return the ‘Content’ of the Invoke-Webrequest
cmdlet inside your Powershell terminal.
Note, the contents of the variable will be in JSON format so I recommend using the ConvertFrom-Json
cmdlet to make the data coherent:
$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json
If you are looking to dump contents to your desktop, you can pipe the $response
variable to the Export-CSV
cmdlet, with the destination -Path
being the UNC to your desktop folder.
Tip: Using the $env:username
variable is a quick way to pull the user name of the person running the script:
$response | Export-Csv -Path C:\Users\$env:username\Desktop\csv-output.csv -NoTypeInformation -Force
If we put it all together we get something like this:
$apiKey = 'xxxx-xxxx-xxxx-xxxx-xxxx'
$orgID = 'xxxx'
$headers = @{ "Authorization" = "Bearer $apiKey" }
$url = "https://console.automox.com/api/servers?o=$orgID&page=0&limit=500"
$response = (Invoke-WebRequest -Method Get -Uri $url -Headers $headers).Content | ConvertFrom-Json
$response | Export-Csv -Path C:\Users\$env:username\Desktop\csv-output.csv -NoTypeInformation -Force
More on getDevices API call can be found here.
I’d also recommend checking out this post for retrieving a hardware inventory from your Automox console. This script includes pagination which is a nice touch.
Have a great day!