new1234.jpg
Home > VMware > VMware: Add PortGroup to all hosts in cluster with PowerCLI

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!

The script:

Get-Cluster “clustername” | Get-VMHost | Get-VirtualSwitch -Name “vSwitch0” | New-VirtualPortGroup -Name “VLAN-23-Citrix Provisioning” -VLanId 23

image

image

Voila!

sanderdaems

Sander Daems is founder and author of this blog and working as a Sr. Infrastructure Consultant by IT-Value. Sander has over 10 years experience in IT, primary focus: virtualization, storage and SBC

More Posts - Website

Follow Me:
TwitterLinkedIn

  1. pcmrbztt
    May 5th, 2011  (Quote) at 15:45  (Quote) | #1

    Nice oneliner, always handy

  2. getoks
    May 7th, 2011  (Quote) at 12:42  (Quote) | #2

    Great

  3. John
    May 29th, 2011  (Quote) at 03:43  (Quote) | #3

    Excellent, this is not a default policy isnt it?

  4. August 10th, 2011  (Quote) at 17:05  (Quote) | #4

    Thank you – saved me a lot of work. Maybe I should have spend some more time looking into scripts than add VLANs mindlessly 🙂

  5. Jean-Baptiste
    December 7th, 2011  (Quote) at 13:16  (Quote) | #5

    Thank you.
    It is realy helpfull.

  6. Dave
    October 21st, 2014  (Quote) at 11:10  (Quote) | #6

    Just started in VMware scripting and this is a great one-liner! Thanks for sharing 🙂

  7. tom
    June 24th, 2015  (Quote) at 04:32  (Quote) | #7

    Thank you, you’re still helping someone….. 🙂

  8. Jack
    October 15th, 2015  (Quote) at 14:36  (Quote) | #8

    Hi
    it doesn’t work for me.
    after I apply command i get prompt like that: “>>”.
    nothing executes.

  9. Jack
    October 15th, 2015  (Quote) at 14:48  (Quote) | #9

    ok, i know.
    I had to write vSwitch0 without quotation marks.

  10. Takahiro
    December 21st, 2015  (Quote) at 03:51  (Quote) | #10

    Thanks =0)

  11. Grzeg
    March 8th, 2016  (Quote) at 15:15  (Quote) | #11

    REALLY nice! Thank you for sharing.

  12. Mahesh
    September 30th, 2016  (Quote) at 02:12  (Quote) | #12

    Thanks. It saves a lot of time.

  1. at | #1
  2. at | #2
  3. at | #3