getting “Exception calling ”GetResponse" while getting cache size in kemp using powershell script

I am trying to get cache size from Kemp server using power shell script. Following is thew script I am using to do so. But keep getting "Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: An unexpected error occurred on a send"

$uri = "https://10.0.0.1/access/get?param=cachesize"

$username = "bal" $password = "XXXXXXX" strong text

$secPw = ConvertTo-SecureString $password -AsPlainText -Force

$Credential = New-Object PSCredential -ArgumentList $username,$secPw

[System.Net.ServicePointManager]::Expect100Continue = $true [System.Net.ServicePointManager]::MaxServicePointIdleTime = 10000 [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $request = [System.Net.HttpWebRequest]::Create($uri) $request.Credentials = $Credential

$response = $request.GetResponse() $response $stream = $response.GetResponseStream() if($response.contenttype -eq "text/xml") { $Encoding = [System.Text.Encoding]::GetEncoding("utf-8") $reader = New-Object system.io.StreamReader($stream, $Encoding) $result = $reader.ReadToEnd() $result if ($result.response.success) { if ([string]::IsNullOrEmpty($result.response.success.data)) { Write-Output $result.response.code } else { Write-output $result.response.success.data } } else { Write-Output $result.response } }

please guide what is causing this error. Not good in powershell.

Parents
  • What you have submitted does is not really complete enough to see what you are really doing.

    What version of PowerShell are you using?
    Are you using the Kemp PowerShell module?

    'support.kemptechnologies.com/hc/en-us/articles/203863385-PowerShell'

    Be aware that it has its own impacts.
    'support.kemptechnologies.com/hc/en-us/community/posts/115009479906-KEMP-PowerShell-Module-Breaks-Native-Windows-RemoteAccess-Commands'

    Note, that when calling after web information, you'd use either the Invoke-WebRequest and / or Invoke-RestMethod if you are on v3 or higher. If you are below that, then you'd have to leverage the .Net framework directly. Specifically [System.Net.WebRequest] and / or [System.Net.HttpWebRequest]. The Kemp PoSH modules leverage RestApi to do it's work. In according to it's own documentation.
Reply Children