0

I am using a PowerShell module provided by Citrix to invoke the Nitro REST API. Calling the function I can successfully add and remove load balanced services from the load. However when I try to do a GET method to get the status of a service I get the error:

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.

I have tried running Invoke-RestMethod without using the module but get the same error

Invoke-RestMethod -WebSession $myNSSession.WebSession -Method GET -Uri https://<NetScaler IP/nitro/v1/config/service/<Service Name>

When googling this error everything seems to point to certificate issues. I had this initially even on POST method until i added the below to my script

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

So since this works for doing POST i cant see why it wouldn't for a GET!!

another weird thing is, if I put the URL directly into the browser then enter my credentials i get a response in raw text! so it looks like this is an issue with the way i am calling it in PowerShell rather than the NetScaler or the NITRO API!

Someone please help as this is driving me crazy!!

Glenn
  • 65
  • 9
  • I had the same problem, this worked for me http://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error?rq=1 – mattnicola May 01 '17 at 04:02

2 Answers2

0

Admitedly i am new to Invoke-RestMethod commands, but try this:

$creds = Get-Credential

$service = Invoke-RestMethod -Uri https://<NetScaler IP/nitro/v1/config/service/<Service Name> -Credential $creds

What you will get is something similar to this:

*errorcode* *message*       *serverity*           *service*
*        0   Done            NONE                  {@{name=<service name; n..

then type $service.service and you will see more information. whatever attributes are availible will be listed. then just follow the pattern: $service.service.

cmwoodman
  • 65
  • 7
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – Kmeixner Jun 08 '15 at 17:44
  • @Kmeixner I don't think that with 1 rep an account can comment on posts that they didn't author. – mortenya Jul 06 '15 at 21:25
0

I had the same problem with Nitro API (specifically v10.5), and found that setting certificate policies, TLS versions and trust settings had no effect. POST works, GET fails.

The solution for me was to not use the cmdlets and instead drop back to a native .Net method. Below I am still using HTTPS with an internal certificate, hence still setting the callback.

$NSProtocol = "https://"
$NSHostname = "netscaler"

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$WebRequest = [System.Net.WebRequest]::Create("$NsProtocol$NsHostname/nitro/v1/config/hanode")
$WebRequest.Method = "GET"
$WebRequest.ContentType = "application/json; charset=utf-8";
$WebRequest.Headers.Add("AUTHORIZATION","Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($nsuser+":"+$nspass)))")
$Response = $WebRequest.GetResponse()
$ReadStream = New-Object System.IO.StreamReader $Response.GetResponseStream()
$HaState = ConvertFrom-Json $ReadStream.ReadToEnd()

Hope that helps.

Trolley01
  • 19
  • 1
  • 5