Really like what your trying to do with your script, We are trying to talk to our on premise CW server and keep on getting the following error when connecting.
$Result = Invoke-CWMWebRequest -Arguments $WebRequestArguments
VERBOSE: Using API Key authentication
VERBOSE: Validating authentication
VERBOSE: GET https://CWServerURL/v4_6_release/apis/3.0/system/info with 0-byte payload
Invoke-CWMWebRequest :
At line:405 char:23
+ ... $Result = Invoke-CWMWebRequest -Arguments $WebRequestArguments
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CWMWebRequest
Connection has been halted.
VERBOSE: $CWMServerConnection, variable removed.
I think its because one of the variables isn't working correctly further down in the code isn't piping a variable through but could be off the mark