VMware PowerCLI Installing the Module and Working with ESXi Host and vCenter

Installing VMware PowerCLI with PowerCLI module.

Run the command to check  VMware PowerCLI installed or Not.
Get-Module VMware.PowerCLI -ListAvailable
Installing the latest version of the module available from PowerShell gallery. Run Below Command to find the Module and Version.
Find-Module VMware.PowerCLI or (Find-Module VMware.PowerCLI).version

12.1.0.17009493 is the latest version that is available in PSGallery.

To install this module use: Install-Module VMware.PowerCLI

Once successfully installed you can verify using: Get-Module VMware.PowerCLI -ListAvailable


To list all the available cmdlets: Get-Command -Module VMware*


Now, let’s go ahead and connect to an ESXi host.Connect-VIServer <IP of ESXi server>



when trying to connect to ESXi host if show error please set the certification ignore and try again to Provide the necessary credentials and once connected successfully you will see the above.
To get details of the ESXi host: Get-VMHost <IP of ESXi server>

Working with vCenter server using VMWare.PowerCLI

Connect-VIServer <IP of vCenter server>

Get the list of data centers present under this vCenter server: Get-Datacenter

Get the list of clusters under a datacenter: Get-Datacenter nkcode-dc01 | Get-Cluster

 

To verify the status of HA, DRS, and vSAN of a cluster:

(Get-Cluster Cluster01) | select Name,DrsEnabled,DrsAutomationLevel,HAEnabled,HAFailoverLevel,VsanEnabled

 

Get the list of ESXi hosts part of a specific cluster:

Get-Datacenter nkcode-dc01 | Get-Cluster Cluster01 | Get-VMHost

 

To get the list of VMs hosted on a specific ESXi host:

Get-Datacenter nkcode-dc01 | Get-Cluster Cluster01 | Get-VMHost 192.168.1.130 | Get-VM

 

To get a list of powered on and powered off VMs:

(Get-Cluster Cluster01 | Get-VM).where{$PSItem.PowerState -eq “PoweredOn”}

(Get-Cluster Cluster01 | Get-VM).where{$PSItem.PowerState -eq “PoweredOff”}

 

An efficient way of doing it in a single go is given below:

$vmson, $vmsoff = (Get-Cluster Cluster01 | Get-VM).where({$PSItem.PowerState -eq “PoweredOn”}, ‘split’)

 

$vmson will have the list of VMs that are PoweredOn and $vmsoff will have the list of VMs that are PoweredOff.

 

Cluster level inventory:

Get-Cluster | Get-Inventory

 

Datastore details of a cluster:

Get-Cluster | Get-Datastore | select Name, FreeSpaceGB, CapacityGB, FileSystemVersion, State