Posted in : Citrix, Powershell By Stina Perbo Utas Translate with Google ⟶

4 years ago

While working with the Citrix Cloud monitor service is amazing, it is also quite unpredictable and we often experience bugs without any notice.

The latest one is related to paging, where the nextLink is presented as http instead of https, which breaks recursive searches. Now this is not the hardest one to fix, but the message can throw you off a bit.

The error states ”Authroization or Customer header is unavailable.” (before you ask, yes the error message is misspelled). And when built into a recursive function It’s not the easiest to spot.

Invoke-WebRequest : Access denied to query Monitor objects : Authorization or Customer header is unavailable.
At line:1 char:1
+ Invoke-WebRequest -Uri 'http://{customerId}.xendesktop.net/Citrix/Mon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

The solution is simple, just replace http:// with https:// and everything will start working again.

Full recursive function

Function Invoke-WebRequestRecursive {
Param(
    $uri,
    $headers
)
    $Ret = Invoke-WebRequest -Uri $uri -Headers $headers -UseBasicParsing -ErrorAction Stop
    [array]$Value = @()
    $Value += (($Ret).Content | ConvertFrom-Json).Value
    If(($ret.Content | ConvertFrom-Json)."@odata.nextLink"){
        $nUri = ($ret.Content | ConvertFrom-Json)."@odata.nextLink".Replace('http://','https://')
        $Value += Invoke-WebRequestRecursive -uri $nUri -headers $headers
    }
    Return $Value
}

Hopefully this save someone a headache or two!

I’ve submitted this as an issue in citrix github so hopefullt this will be resolved soon.

Issue:
https://github.com/citrix/monitoring-api/issues/12

Citrix Developer API
https://developer-docs.citrix.com/projects/access-monitor-service-data-citrix-cloud/en/latest/

Tags : API, Citrix, Citrix Monitor API, Microsoft, OData API, PowerShell

Personlig rådgivning

Vi erbjuder personlig rådgivning med författaren för 1400 SEK per timme. Anmäl ditt intresse i här så återkommer vi så snart vi kan.

Add comment

Your comment will be revised by the site if needed.