AutomoxAutomox

Worklet to pull device patching logs stopped working with error

JHagstrom
April 19, 2022 at 10:15 pm UTC

Hello!
I have a worklet that has been running weekly for months with no issue, the worklet essentially grabs patching logs from each device in Automox and exports them all to a CSV. I noticed on around January 18th of 2022 that the script started reporting nothing so I ran the code locally and am getting an error:
 

powershell7 lines
Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel.
At line:11 char:13
+ $response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I know Automox has the limitation of no more than 500 results when pulling from the API, but I am well under half that. Here is the full script for context:

powershell32 lines
#Set Execution policy to allow for 3rd party modules
Set-ExecutionPolicy Unrestricted -Force

#Define API Key and URL to get initial Machine list
$apiKey = "APIKEY"
$apiUrl = "https://console.automox.com/api/servers/"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $apiKey")
#$headers.Add("Cookie", "ax_session=CENSORED")

$response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json

$time = (Get-Date).ToString("yyyy-MM-dd-HH")
Export-Csv "C:\Automox_Patch_Exports\Patch_Export_$((Get-Date).ToString("yyyy-MM-dd-HH")).csv" -NoTypeInformation

$name = $server.name;

#For each machine get the patch info according to machine ID and Org.
foreach($server in $response){
    #Define Server ID, Org ID, and Group ID.
    $id = $server.id
    $organization_id = $server.organization_id
    $server_group_id = $server.server_group_id

    $apiUrl = "https://console.automox.com/api/servers/$($id)/packages?o=$($organization_id)"
    $response = Invoke-RestMethod $apiUrl -Method 'GET' -Headers $headers -Body $body
    #Define which objects you want to be included in the CSV. See (Under "Response") for full list:	https://docs.automox.com/api/endpoints/list-software-packages-for-a-device
    $DesiredProperties = $response | Select-Object $server.name, installed, create_time, display_name, package_id, software_id, cve_score
    #Add the information to the CSV.
    $DesiredProperties | ConvertTo-Csv -NoTypeInformation | Add-Content -Path "C:\Automox_Patch_Exports\Patch_Export_$time.csv"
}

Tried researching the specific error, but was not able to come up with much so wanted to check with Automox while I kept troubleshooting on my own.

Thanks in advance for any tips :)
 

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (1)

JHagstromApril 20, 2022
#1

Solved the issue. Was something firewall related.