VMware PowerCLI Cheatsheet
#
VMware PowerCLI is a powerful command-line tool for automating and managing VMware vSphere environments using PowerShell. It provides cmdlets for managing vCenter Server, ESXi hosts, virtual machines, storage, and networking.
Getting Started
#
Command/Option | Example | Description |
---|
Install-Module -Name VMware.PowerCLI | Install-Module -Name VMware.PowerCLI | Install PowerCLI module |
Connect-VIServer | Connect-VIServer -Server <vcenter_server> | Connect to a vCenter Server |
Disconnect-VIServer | Disconnect-VIServer -Server <vcenter_server> | Disconnect from a vCenter Server |
Virtual Machine Management
#
Command/Option | Example | Description |
---|
Get-VM | Get-VM -Name <vm_name> | Retrieve information about a virtual machine |
Start-VM | Start-VM -VM <vm_name> | Start a virtual machine |
Stop-VM | Stop-VM -VM <vm_name> -Confirm:$false | Stop a virtual machine without confirmation |
New-VM | New-VM -Name <vm_name> -ResourcePool <pool_name> -Template <template_name> | Create a new virtual machine from a template |
Remove-VM | Remove-VM -VM <vm_name> -DeletePermanently -Confirm:$false | Remove a virtual machine permanently |
vCenter Server Management
#
Command/Option | Example | Description |
---|
Get-Datacenter | Get-Datacenter -Name <datacenter_name> | Retrieve information about a datacenter |
New-Datacenter | New-Datacenter -Name <datacenter_name> | Create a new datacenter |
Remove-Datacenter | Remove-Datacenter -Name <datacenter_name> -Confirm:$false | Remove a datacenter without confirmation |
Get-Cluster | Get-Cluster -Name <cluster_name> | Retrieve information about a cluster |
New-Cluster | New-Cluster -Name <cluster_name> -Location <datacenter_name> | Create a new cluster in a datacenter |
Remove-Cluster | Remove-Cluster -Name <cluster_name> -Confirm:$false | Remove a cluster without confirmation |
Host Management
#
Command/Option | Example | Description |
---|
Get-VMHost | Get-VMHost -Name <host_name> | Retrieve information about an ESXi host |
Add-VMHost | Add-VMHost -Name <host_name> -Location <cluster_name> -User <username> -Password <password> | Add a new ESXi host to a cluster |
Remove-VMHost | Remove-VMHost -VMHost <host_name> -Confirm:$false | Remove an ESXi host without confirmation |
Set-VMHost | Set-VMHost -VMHost <host_name> -State Maintenance | Set an ESXi host to maintenance mode |
Network Management
#
Command/Option | Example | Description |
---|
Get-VirtualSwitch | Get-VirtualSwitch -VMHost <host_name> | Retrieve information about virtual switches |
New-VirtualSwitch | New-VirtualSwitch -VMHost <host_name> -Name <vSwitch_name> | Create a new virtual switch |
Remove-VirtualSwitch | Remove-VirtualSwitch -VMHost <host_name> -Name <vSwitch_name> -Confirm:$false | Remove a virtual switch without confirmation |
Get-VirtualPortGroup | Get-VirtualPortGroup -VirtualSwitch <vSwitch_name> | Retrieve information about port groups |
New-VirtualPortGroup | New-VirtualPortGroup -VirtualSwitch <vSwitch_name> -Name <portgroup_name> -VLanId <vlan_id> | Create a new port group |
Remove-VirtualPortGroup | Remove-VirtualPortGroup -Name <portgroup_name> -Confirm:$false | Remove a port group without confirmation |
Storage Management
#
Command/Option | Example | Description |
---|
Get-Datastore | Get-Datastore -Name <datastore_name> | Retrieve information about datastores |
New-Datastore | New-Datastore -VMHost <host_name> -Name <datastore_name> -Path <path> | Create a new datastore |
Remove-Datastore | Remove-Datastore -Name <datastore_name> -Confirm:$false | Remove a datastore without confirmation |
Get-ScsiLun | Get-ScsiLun -VMHost <host_name> | Retrieve information about SCSI LUNs |
New-ScsiLun | New-ScsiLun -VMHost <host_name> -CanonicalName <canonical_name> -MultipathPolicy <policy> | Create a new SCSI LUN |
Remove-ScsiLun | Remove-ScsiLun -VMHost <host_name> -CanonicalName <canonical_name> -Confirm:$false | Remove a SCSI LUN without confirmation |
Snapshots
#
Command/Option | Example | Description |
---|
Get-Snapshot | Get-Snapshot -VM <vm_name> | Retrieve information about snapshots of a VM |
New-Snapshot | New-Snapshot -VM <vm_name> -Name <snapshot_name> | Create a new snapshot of a VM |
Remove-Snapshot | Remove-Snapshot -VM <vm_name> -Name <snapshot_name> -Confirm:$false | Remove a snapshot without confirmation |
Set-Snapshot | Set-Snapshot -VM <vm_name> -Name <snapshot_name> -Description "New description" | Update snapshot description |
This cheatsheet covers the most commonly used VMware PowerCLI commands and options, helping you to manage virtual machines, vCenter servers, ESXi hosts, networks, storage, and snapshots effectively.