Kemp LoadMaster RESTful API Mangement with Powershell

There are several articles explaining how to access and manage the Kemp LoadMaster with the RESTful API. However, there are not very many articles that show you how to connect via Powershell. I attempted to follow several articles, but I kept running into problems.  Primarily the following:

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

Everything that I did could not solve this problem. I found several articles stating that I would need to tell powershell to ignore certificate problems or force powershell to use TLS 1.2 before calling the invoke-restmethod cmdlet.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

However, this did not work for me at all!  The problem is related to the invoke-restmethod and invoke-webrequest cmdlets run in their own runspace.

Follow this procedure!

Powershell code to connect to the Kemp Loadmaster and list the virtual services

$pass = Get-Content "c:\scripts\KempPassword.txt" | ConvertTo-SecureString
$User = "YourKempUserAccount"
$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $pass>
$kempurl = ""
$uri = $kempurl+"/access/listvs"
[string]$response = Invoke-RestMethod $uri -Credential $MyCredential


In the example above, I am using a encrypted password that was saved in a KempPassword.txt file. You can generate this password by executing:

"P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString

The Kemp LoadMaster will return an xml response that will need to be parsed as required. Here are two websites that I used to parse the xml in powershell:



Previous Articles on the Kemp API and Powershell (did not work for me)

Kemp’s API and Powershell documentation



About Parker Jardine

Manager of Systems Administration in the Information Technology Higher Education space. I enjoy biking, climbing, hockey, camping, mountaineering, hunting, paragliding, and just being outdoors. You can read my Make Magazine project articles about a diy solar panel and solar systems design in volumes 12 and 14.
This entry was posted in API Programming, Kemp LoadMaster, Powershell and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s