Getting started with VMware PowerCLI – Ken Shelton
Getting started with VMware PowerCLI
VMware PowerCLI has become an essential tool for a VMware admin to perform daily tasks as well as for performing automation. The sky is the limit for what can be done leveraging PowerCLI! Everything from basic tasks like taking an inventory of all VM’s to deploying and configuring an entire new cluster – and everything in between. But you may be wondering where to get started and that is the goal of this blog. I will introduce how to get PowerCLI installed, how to connect to the vSphere infrastructure, and some basic commands to get started.
The PowerCLI modules are installed from the PowerShell Gallery which makes installation extremely easy. Typically, you will just run a single command to have all PowerCLI modules installed, but modules can be installed individually.
- Open PowerShell as Administrator
- Run the following command to install PowerCLI
Install-Module VMware.PowerCLI -Scope CurrentUser
- You may see a warning about installing from an untrusted repository. If so, simply press “y” and then Enter to confirm installation. VMware PowerCLI modules will begin installing.
- After installation, you can choose whether to participate in the VMware Customer Experience Improvement Program or not. I like going ahead and configuring this, so it does not prompt me later. It is as simple as running the following command and setting either true or false depending on whether you wish to participate or not.
Set-PowerCLIConfiguration -Scope User -ParticipateInCeip $false
- Press Enter to confirm the update to PowerCLI configuration.
Connecting to vCenter
Now that PowerCLI is installed, connecting to the vSphere infrastructure is now possible. This is achieved by connecting to vCenter. While connecting to multiple vCenter’s is possible, we will focus on getting connected to a single vCenter instance here.
- Open PowerShell
- Run the following command to connect to vCenter and supply the vCenter FQDN for the Server parameter.
Connect-VIServer -Server vcenter_fqdn
- Supply credentials to login to vCenter when prompted.
Once credentials are verified, you are now connected to vCenter.
Well, you are connected to vCenter – now what? Starting out, I would recommend just running “Get” commands. This will help get you acclimated to available PowerCLI commands as well as basic command syntax. Plus, the “Get” commands to do just that – get information. So, this is low risk to the environment as nothing will be changed. Here are 2 commands to get you started.
You got it; this command will return ALL VM’s in the connected vCenter’s inventory. Whether you have a single host or multiple clusters, you will get all VM’s returned.
So, let us not forget about the physical hosts all those VM’s run on. This command will return ALL host’s in the connected vCenter’s inventory.
From these 2 examples, you can already begin to see how straightforward using PowerCLI can be and the loads of great information you are able to return quickly. Do not forget the same great help system in PowerShell is available for the PowerCLI cmdlets as well.
Try running the Get-Help command:
This will return a description on what the command does as well as syntax!
So, I hope this information was helpful and encourages you to get started with PowerCLI if you have never tried it before. The few commands I showed is not even scratching the surface on what is possible using this powerful tool. I plan to write more articles in the future on PowerCLI, so keep a lookout for those! In the meantime, check out the links below for PowerCLI documentation. Particularly, the Cmdlet Reference is awesome for quick reference on all available commands and how to use them!
PowerCLI 12.3.0 User’s Guide
VMware vSphere and vSAN PowerCLI Reference