PSAtera
PSAtera copied to clipboard
Weird error on some machines.
So this is the first part of the script. It runs on 99/100 machines. Just a few I get error below. Running it step by step, the "Set-AteraAPIKey -APIKey $AteraAPIKey" doesn't do a thing.
$AteraAPIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ClientCustomValueName = "CUSTOMFIELD"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
# Install and load the right version of Atera
if (!(Get-Module -ListAvailable PSAtera)) {
Install-Module -Name PSAtera -MinimumVersion 1.7.0 -Force
}
Import-Module -Name PSAtera -MinimumVersion 1.7.0
Set-AteraAPIKey -APIKey $AteraAPIKey
$Agent = Get-AteraAgent
$GetCustomFieldContents = Get-AteraCustomValue -ObjectType Customer -ObjectID $Agent.customerID -FieldName $ClientCustomValueName
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\PSAtera\1.7.0\PSAtera.psm1:43 char:13
+ $data = Invoke-RestMethod -Uri $Uri -Method "GET" -Headers $Heade ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
n
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Does it all the time fails on that specific computer? If not, are you aware of API rates? Atera limits calls per second.
I don't use Atera anymore, but I would expect them to return a 401 if the API Key was missing from the request. Do you get back the correct API key if you run Get-AteraAPIKey?
You can get debug output if you add $DebugPreference = 'Continue' and that should give you some help toward figuring out the issue.