Log in to https://my.vmware.com/web/vmware/login and download the VMware vSphere PowerCLI 6.0 release 1 or release 2. We have used the PowerCLI 6.0 R 1 in this appendix, but R 2 is publically available to download:
Double click on the downloaded file to start the installation wizard, as shown in the following screenshot:
Click on Next and accept the following agreement:
In the next window, you can choose the features that you would like to install. In previous versions of PowerCLI, vCloud or vCD PowerCLI, these features are not installed by default. In PowerCLI 6.0, vCloud Air/vCD PowerCLI is already enabled by default. We will install vCD PowerCLI as we have a vCloud Director installed. You can choose to disable it according to your environment. Click on Next:
Click on Finish once the installation wizard is completed:
Open the installed vSphere PowerCLI via the shortcut on your desktop. You will be presented with a welcome message and some basic commands as a reference to start with, as shown in the following screenshot:
Before we start executing scripts or running commands, we need to check the execution policy. To check that, we can type the following command in our PowerCLI of vSphere or Windows PowerShell:
Get-ExecutionPolicy
If it is set to restricted, which is the default policy, you will not need to execute scripts. To enable it, type the following, as shown in the next screenshot, and type Y
to accept it:
Set-ExecutionPolicy –ExecutionPolicy RemoteSigned
To connect to a vCenter Server, type the following:
Connect-VIServer 10.5.2.229
Once prompted, enter your username and password, and click on OK. You will see the output in the PowerCLI of the vCenter Server Name or IP address, the port it is connected to, and the user name that is being used for the connection:
You can see the list of recently connected vCenter Servers or vSphere hosts by typing the following command:
Connect-VIServer - Menu
Now the vCenter Server is connected to retrieve a list of virtual machines currently hosted. To do this, you can type the following:
Get-VM
You can see the list of virtual machines in the following screenshot:
To get more information about the hard disk of the vCenter005 virtual machine, type the following:
Get-VM –Name vCenter005 | Get-HardDisk
To list modules, type the following:
Get-Module -ListAvailable VMware*
The Get-Module
command will list all the available modules to be imported in PowerCLI.