Expanding the Lab
I’ve been working on changing some things in my lab lately, and wanted to build a jumphost that I could get to from anywhere and use it to work on my VMware Virtualization lab. While it would be pretty easy to setup a Windows machine, my lab dollars are hard to come by and I wanted to save every bit to grow the capacity. Ever since PowerShell was made available on multiple platforms, I’ve wanted to try it out on Linux.
I am in no way a Linux expert; but have worked in multiple distros and am fairly comfortable – at least for non-production use. I set up a VM with Ubuntu Desktop and applied all of the patches. I’ll let others debate the virtues of the various Linux distributions. I picked Ubuntu a while ago and it seemed to make sense to focus on a single distribution to best develop my expertise. I chose Ubuntu Desktop as I wanted to have a GUI available should I be working remotely and needed to do a demo or work though something requiring a browser.
What do I need?
The toolset I need for my jumphost is fairly easy to assemble:
- Modern Web Browser – Chrome and Firefox
- PowerShell – This is Microsoft’s command-line shell and scripting language. In the multi-cloud world in which we live in – this can be the tool to help automate all of these platforms together
- PowerCLI – PowerCli is a PowerShell module for managing VMware vSphere
- Tools for future projects (such as Restful API automation, Desired State Configuration , etc)
As this is the initial build-out, this article will focus on installing PowerShell and PowerCLI. There are two ways to install Powershell on Linux:
- Download the installer and run this on your target machine.
- You can also update the repository list on your machine and install the package.
For more details on the two methods, check out the Microsoft documentation for PowerShell Core.
My Ubuntu Linux VM is already confgured, patched and ready to go. If you haven’t done this yet, this tutorial can help you get started.
I opted to add PowerShell to my repository list as this would help keep the package updated as I patch the machine. In a terminal window, enter the following commands to download the Microsoft Repository signature and then install it to your repo config.
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-deb
Now we need to refresh the package lists to include those from the new repository.
sudo apt-get update
Once this has been done we can install PowerShell.
sudo apt-get install -y powershell
PowerShell is installed and ready to go! To start PowerShell just type pwsh in a Linux shell.
The next step is to install the PowerCLI module. Tip: when installing new modules into PowerShell, you must escalate privileges when you invoke PowerShell.
On to installing the PowerCLI module.
install-module -name VMware.PowerCLI
You will see a simple status while PowerCLI is installed.
So that’s it right? With PowerShell and PowerCLI both installed, I should be able to run some commands against vCenter and start automating!
Getting to work
Let’s use PowerShell to connect to our vCenter and explore what we can do…
Connect-VIServer -server vcsa.cybersylum.com -user [email protected] -pass Don'tSharePasswords!
Since I am using the default self-signed certificate in my lab, I will get an error. Fortunately, we can tell PowerCLI to ignore this issue if need be:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Now we should be able to connect to the vCenter server in the lab and run a basic command to list all VMs.
Connect-VIServer -server vcsa.cybersylum.com -user [email protected] -pass Don'tSharePasswords! get-vm
That’s it – now you can run PowerShell from your Linux machine and build scripts to automate your VMware environment! This is a very trivial example of what can be done. PowerShell and PowerCLI together make a very powerful swiss army knife!
In future posts, I will discuss what you can do with PowerShell and PowerCLI now that you have it up and running. If you haven’t done much with these tools and are eager to learn – there are a number of links with tips on getting started with PowerCLI in my vToolBelt posts you might want to check out.