Barracuda Load Balancer- Powershell

Great_Barracuda_off_the_Netherland_AntillesWorking on my Powershell skills, I was playing around with a Barracuda Load Balancer and noticed it supported some APIs which is kind of cool. At first I was playing around with it in postman and got to login and put some servers in maintenance mode, but then thought it would be really neat if I could get this working in Powershell, that way us humans can just run a script and even thinking in the “future” maybe have some automated process (a.k.a AI) handle this for us. 😉 So in this post I’ll talk about the script I created and some of the small challenges I had with this overall it was kind of neat putting this together.

TLDR: Here is the script if you don’t want to read:

The first thing I was stuck on was the way Barracuda uses the API token, I was able to have to load balancer give me the token but Powershell also wanted a password with that API token. Barracuda only uses the username as the token to login. So I needed to configure Powershell to null the password when logging with the API token. A quick search on the web led me to create the $lbcred variable.

Another small gotcha was when using the default version of Powershell on Windows 10 I was having a problem with the login and really didn’t want to create a curl header or anything like that. I also wanted to keep the username and password out of the script. When you run the script it will ask you what the username and password is and use that while the script it running, I thought it would be easier. So when researching this, and I didn’t actually know this but there are different updated versions of Powershell which are available on GitHub and they work different operating systems besides Windows. So that’s pretty cool, and also tells you how much I pay attention to Powershell :).

When looking at the release notes for Powershell 6.0.4 they made some modifications to the Invoke-RestMethod command for -Authentication switch so I downloaded Powrshell 6.0.4 and then found it does not work with Powershell ISE. 😦

Which is what I have been using and I now needed to download Visual Studio Code which is a free download and install  the Powershell extenstion so that I could run it within that program. Again just goes to show you how much I know about this stuff. After all of that I was able to login into the load balancer using the token API!

The last command I just needed a json to tell the load balancer want I wanted to do with the servers, I could put them in maintenance, enable or disable status and if I had more than one server in the load balancer, I just copied the command again and used a different variable for each server. After that I was able to put servers in a different via Powershell!

Advertisements

Leave a Reply...

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

WordPress.com Logo

You are commenting using your WordPress.com 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