VMware PowerCLI

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/OptionExampleDescription
Install-Module -Name VMware.PowerCLIInstall-Module -Name VMware.PowerCLIInstall PowerCLI module
Connect-VIServerConnect-VIServer -Server <vcenter_server>Connect to a vCenter Server
Disconnect-VIServerDisconnect-VIServer -Server <vcenter_server>Disconnect from a vCenter Server

Virtual Machine Management #

Command/OptionExampleDescription
Get-VMGet-VM -Name <vm_name>Retrieve information about a virtual machine
Start-VMStart-VM -VM <vm_name>Start a virtual machine
Stop-VMStop-VM -VM <vm_name> -Confirm:$falseStop a virtual machine without confirmation
New-VMNew-VM -Name <vm_name> -ResourcePool <pool_name> -Template <template_name>Create a new virtual machine from a template
Remove-VMRemove-VM -VM <vm_name> -DeletePermanently -Confirm:$falseRemove a virtual machine permanently

vCenter Server Management #

Command/OptionExampleDescription
Get-DatacenterGet-Datacenter -Name <datacenter_name>Retrieve information about a datacenter
New-DatacenterNew-Datacenter -Name <datacenter_name>Create a new datacenter
Remove-DatacenterRemove-Datacenter -Name <datacenter_name> -Confirm:$falseRemove a datacenter without confirmation
Get-ClusterGet-Cluster -Name <cluster_name>Retrieve information about a cluster
New-ClusterNew-Cluster -Name <cluster_name> -Location <datacenter_name>Create a new cluster in a datacenter
Remove-ClusterRemove-Cluster -Name <cluster_name> -Confirm:$falseRemove a cluster without confirmation

Host Management #

Command/OptionExampleDescription
Get-VMHostGet-VMHost -Name <host_name>Retrieve information about an ESXi host
Add-VMHostAdd-VMHost -Name <host_name> -Location <cluster_name> -User <username> -Password <password>Add a new ESXi host to a cluster
Remove-VMHostRemove-VMHost -VMHost <host_name> -Confirm:$falseRemove an ESXi host without confirmation
Set-VMHostSet-VMHost -VMHost <host_name> -State MaintenanceSet an ESXi host to maintenance mode

Network Management #

Command/OptionExampleDescription
Get-VirtualSwitchGet-VirtualSwitch -VMHost <host_name>Retrieve information about virtual switches
New-VirtualSwitchNew-VirtualSwitch -VMHost <host_name> -Name <vSwitch_name>Create a new virtual switch
Remove-VirtualSwitchRemove-VirtualSwitch -VMHost <host_name> -Name <vSwitch_name> -Confirm:$falseRemove a virtual switch without confirmation
Get-VirtualPortGroupGet-VirtualPortGroup -VirtualSwitch <vSwitch_name>Retrieve information about port groups
New-VirtualPortGroupNew-VirtualPortGroup -VirtualSwitch <vSwitch_name> -Name <portgroup_name> -VLanId <vlan_id>Create a new port group
Remove-VirtualPortGroupRemove-VirtualPortGroup -Name <portgroup_name> -Confirm:$falseRemove a port group without confirmation

Storage Management #

Command/OptionExampleDescription
Get-DatastoreGet-Datastore -Name <datastore_name>Retrieve information about datastores
New-DatastoreNew-Datastore -VMHost <host_name> -Name <datastore_name> -Path <path>Create a new datastore
Remove-DatastoreRemove-Datastore -Name <datastore_name> -Confirm:$falseRemove a datastore without confirmation
Get-ScsiLunGet-ScsiLun -VMHost <host_name>Retrieve information about SCSI LUNs
New-ScsiLunNew-ScsiLun -VMHost <host_name> -CanonicalName <canonical_name> -MultipathPolicy <policy>Create a new SCSI LUN
Remove-ScsiLunRemove-ScsiLun -VMHost <host_name> -CanonicalName <canonical_name> -Confirm:$falseRemove a SCSI LUN without confirmation

Snapshots #

Command/OptionExampleDescription
Get-SnapshotGet-Snapshot -VM <vm_name>Retrieve information about snapshots of a VM
New-SnapshotNew-Snapshot -VM <vm_name> -Name <snapshot_name>Create a new snapshot of a VM
Remove-SnapshotRemove-Snapshot -VM <vm_name> -Name <snapshot_name> -Confirm:$falseRemove a snapshot without confirmation
Set-SnapshotSet-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.

VMware PowerCLI

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.