Tuesday, June 4, 2013

VMware PowerCLI Reference List

Ever since I started my new job, I've had to increasingly use PowerCLI scripts/commands in order to configure and manage the environments. When you have hundreds of ESXi hosts, it becomes impossible to manually make changes on each and every host via the vSphere Client. This post will be used as a place for me to reference the commands that I use fairly often.


Networking

Add virtual port group to every host in a cluster and tag it with the specific VLAN:

Get-Cluster "DRP" | get-vmhost | Get-VirtualSwitch -name vSwitch0 | new-VirtualPortGroup -name "Production" -vlanid 10


Remove specified virtual port group from every host in a cluster:

Get-Cluster "test" | Get-VMHost | Get-VirtualSwitch -Name "vSwitch0" | Get-VirtualPortGroup -Name "Test" | Remove-VirtualPortGroup







Storage

Change PSP to round robin for all LUNs on all hosts:


Get-Cluster "DRP" | Get-VMHost | Get-ScsiLun -CanonicalName "naa.xxx*" | Set-ScsiLun -MultipathPolicy "roundrobin"


Rescan datastores for new storage devices and new VMFS volumes

Get-Cluster "ClusterName" | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs


Add NFS datastore to all hosts in a cluster

Get-Cluster "Cluster Name" | Get-VMHost | New-Datastore -Nfs -Name "Datastore Name" -Path "/path" -NfsHost "IP address"

No comments:

Post a Comment