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 = ""

$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$stream, $Encoding) $result = $reader.ReadToEnd() $result if ($result.response.success) { if ([string]::IsNullOrEmpty($ { Write-Output $result.response.code } else { Write-output $ } } else { Write-Output $result.response } }

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

  • 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?


    Be aware that it has its own impacts.

    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.
  • In reply to postanote:

    Thank you for the feedback. I am running Windows Powershell version 4.0.

    I have imported kemp module and now I have managed to do it by gettign credentials using the below command:-
    $mycreds = New-Object System.Management.Automation.PSCredential ("xxxxxx", $secpasswd) as somehow it was not supporting New-Object PSCredential -ArgumentList $username,$secPw.

    Thanks for your help.
  • In reply to gigabyte:

    No worries.
    Glad you got to what is a working state for you.

    However, you are using the long way to handle the user credentials. Virtually in all cases it is simpler to use the:
    Get-Credential cmdlet

    # Store the defined users credential in the variable
    $mycreds = Get-Credential -Credential 'domain\username'

    # Show that is in the variable

    UserName Password
    -------- --------
    domain\username System.Security.SecureString

    Then use $mycreds whenever credentials are needed.

    Or just look at the parts