In part one of this multi-part series, we took a look at downloading and installing VMware vSphere PowerCLI, the free PowerShell snapin for managing your VMware infrastructure. Now we need to do something with it. Today I’ll go through the steps of setting up and configuring PowerCLI.
(Need to catch up? Check out the rest of this series! In part three: use PowerCLI to start and shutdown VMs. In part four: PowerCLI and PSDrives, and in part five: created a new VM. Finally, in part six: use PowerCLI to manage your ISO files.)
Before we can do anything we need to add the snapin to our PowerShell session.
[Note: For modern environments (Windows 10/11 and Windows Server 2019/2022), PowerCLI is now installed as a module via PowerShell Gallery. Use Install-Module -Name VMware.PowerCLI instead of Add-PSSnapin]
PS C:> add-pssnapin vmware.vimautomation.core
If you are ever in doubt about what version you are running, the snapin has a handy command.
PS C:> get-powercliversion PowerCLI Version ---------------- VMware vSphere PowerCLI 5.1 Release 2 build 1012425 --------------- Snapin Versions --------------- VMWare AutoDeploy PowerCLI Component 5.1 build 768137 VMWare ImageBuilder PowerCLI Component 5.1 build 768137 VMware License PowerCLI Component 5.1 build 669840 VMware VDS PowerCLI Component 5.1 build 1012428 VMware vSphere PowerCLI Component 5.1 build 1012428
Now we are ready to manage our environment, but first we need to connect to a server.
[Note: Get-PowerCLIVersion is deprecated in modern versions. Use Get-Module -Name VMware.PowerCLI to check the current module version.]
The cmdlet we need is called Connect-VIServer. Take some time to look at full help and examples. The PowerCLI cmdlets also support online help so you can run a command like this:
PS C:> help Connect-VIServer –online
To connect to a server you need to specify a name or IP address and you need to be authenticated (assuming your current credentials don’t suffice). You can use a saved PSCredential object and specify a username and password, or you can simply run the command and enter credentials when prompted.
PS C:> connect-viserver 172.16.10.111
If you prefer a simple one-line approach, you can even enter the password as part of the command.
PS C:> connect-viserver 172.16.10.111 -user root -Password P@ssw0rd
I’m going to connect with a previously created credential object.
PS C:> connect-viserver 172.16.10.111 -Credential $c
A feature you might want to take advantage of – assuming you need to specify credentials – is to securely keep them in the local credential store. When you logon use the –SaveCredentials parameter.
PS C:> connect-viserver 172.16.10.111 -Credential $c –SaveCredentials
In the future, when you connect to the server all you need to do is specify the server name. Although Connect-VIServer has a cool parameter, -Menu, which will display a text list of recently connected servers.
PS C:> connect-viserver -Menu Select a server from the list (by typing its number and pressingEnter
):
[1] esx.jdhitsolutions.local
[2] 172.16.10.111
2
Name Port User
---- ---- ----
172.16.10.111 443 root
PS C:> [This feature remains available in current versions of PowerCLI as of Windows 11 and PowerShell 7.x.]
The first time you connect you might see a warning like you see below in Figure 1.
In my environment I’m not using any sort of certificates. But I don’t want to be bothered with the warning, so I’ll follow the suggestion and use the Set-PowerCLIConfiguration cmdlet.
PS C:> Set-PowerCLIConfiguration -InvalidCertificateAction ignore
These are the possible values you can use:
You can always run:
PS C:> Get-PowerCLIConfiguration
To see the current configuration and change it any time.
[These certificate handling settings remain unchanged in modern versions of PowerCLI and PowerShell 7.x on Windows 10/11.]
Now that we have that out of the way let’s see what servers we can work with using Get-VMHost.
PS C:> Get-VMHost
In my case, I only have a single ESXi server but you might see more servers listed. You can also specify a host by name.
And as with most objects in PowerShell, there is more to the object than what you see here.
PS C:> get-vmhost | select *

There are some settings you might want to configure, but we’ll cover those in a future article.
As long as you are connected to the server you can perform all sorts of management magic, which I will be discussing later. If you close your PowerShell session you will automatically be disconnected. But you can also manually disconnect.
PS C:> Disconnect-VIServer
This will disconnect you from the server you are currently connected to. You will be prompted for confirmation. If you prefer not to be bothered, set the confirm parameter to false.
PS C:> Disconnect-VIServer -confirm:$false
[PowerCLI 13.x and later versions on Windows 11 and Server 2022 still support these core connection and disconnection workflows.]
I’ve covered several cmdlets for connecting to a VMware infrastructure server and configuring some basic PowerCLI settings. I didn’t cover every possible setting, and your environment may require additional steps. So take the time to read full help and examples for all the cmdlets I’ve demonstrated in this article. Next time we’ll look at some basic virtual machine management.
The set-powercliconfiguration cmdlet allows you to configure automated task scheduling by setting default execution policies, timeout values, and concurrent job limits. This ensures smooth operation of scheduled PowerCLI tasks in your VMware environment.
Yes, set-powercliconfiguration enables you to configure proxy settings, including proxy server addresses, authentication credentials, and bypass lists for specific connections to your VMware infrastructure.
Using set-powercliconfiguration, you can customize PowerCLI logging behaviors, including log file locations, verbosity levels, and retention policies for troubleshooting and audit purposes.
Yes, set-powercliconfiguration allows you to create and manage multiple configuration profiles for different environments, making it easier to switch between development, testing, and production settings.
The set-powercliconfiguration cmdlet enables administrators to set default parameter values for commonly used PowerCLI commands, streamlining routine operations and ensuring consistency across multiple sessions.