What is PowerCLI ?
PowerCLI is a Windows PowerShell interface for managing VMware vSphere.
VMware describes PowerCLI as “a powerful command-line tool that lets you automate all aspects of vSphere management, including network, storage, VM, guest OS and more. PowerCLI is distributed as a Windows PowerShell snapin (PowerCLI 6.0 introduced PowerShell module), and includes over 500 PowerShell cmdlets for managing and automating vSphere and vCloud, along with documentation and samples.”
PowerCLI runs in PowerShell on Windows, macOS, and Ubuntu operating systems.
Useful PowerCLI commands
Before using any command, please connect to your vcenter using this command :
Connect-VIServer -Server vCenter-IP -User administrator@vsphere.local -Password XXXXXX
Get all virtual machines :
get-vm
Get all snapshots in order by date:
get-vm | get-snapshot | sort created -descending | format- list VM,Name,SizeGB,Created
Disconnet from the current vcenter :
Disconnect-VIServer
Print help menu :
get-help *
Shutdown a virtual machine :
Get-VM "MyVM (a5b3275c-ba35-4267-adc0-2e51c22d0ef7)" | Shutdown-VMGuest -Confirm:$false
Start a VM :
Start-VM "MyVM (a5b3875c-ba35-4267-adc0-2e51c22d0ef7)" -Confirm:$false
Get all Affinity Rules from a cluster :
Get-Drsrule -Cluster MyCluster
Deactivate all Affinity Rules from a cluster :
Get-Drsrule -Cluster Cluster-Rsrc02-Mey | Set-DrsRule -Enabled $false (switch to true to reactivate)
Deactivate VMAntiAffinity, VMAffinity and VMHostAffinity rules :
Get-DrsRule -Cluster "Cluster-Name" | Set-DrsRule -Enabled $false Get-DrsVMHostRule -Cluster "Cluster-Name" | Set-DrsVMHostRule -Enabled $false
To go further : RvTools
Another tool you should take a look at is “RVTools” (https://www.robware.net/rvtools/)
RVTools is a windows .NET application which uses the VI SDK to display information about your virtual environments.
RVTools is able to list information about so many components ; VMs, CPU, Memory, Disks, Partitions, Network, Floppy drives, CD drives, Snapshots, VMware tools, Resource pools, Clusters, ESX hosts, HBAs, Nics, Switches, Ports, Distributed Switches, Distributed Ports, Service consoles, VM Kernels, Datastores, multipath info, license info and health checks.
With RVTools you can update the VMware Tools installed inside each virtual machine to the latest version !
Here are all information you can get through RVTools : Link
Sources
- https://wikipedia.org
- https://communities.vmware.com
- https://www.robware.net/rvtools/