VMware: Add PortGroup to all hosts in cluster with PowerCLI
Today we configured a new VLAN on the physical switches, now we need to configure a portgroup with vlan id on multiple ESX hosts in our cluster. To do this by hand it will cost 3 minutes per host, to script this.. you configure this in 10 seconds!
Get-Cluster “clustername” | Get-VMHost | Get-VirtualSwitch -Name “vSwitch0” | New-VirtualPortGroup -Name “VLAN-23-Citrix Provisioning” -VLanId 23
17 thoughts on “VMware: Add PortGroup to all hosts in cluster with PowerCLI”
Nice oneliner, always handy
Excellent, this is not a default policy isnt it?
Thank you – saved me a lot of work. Maybe I should have spend some more time looking into scripts than add VLANs mindlessly 🙂
It is realy helpfull.
Just started in VMware scripting and this is a great one-liner! Thanks for sharing 🙂
Thank you, you’re still helping someone….. 🙂
it doesn’t work for me.
after I apply command i get prompt like that: “>>”.
ok, i know.
I had to write vSwitch0 without quotation marks.
REALLY nice! Thank you for sharing.
Thanks. It saves a lot of time.
thanks, its saved my time.
Can anyone tell me how to add multiple vlan/port groups to one esxi host using csv. Please share me the csv format and script.