VI Toolkit powershell simple script #1 – Create new portgroup

Caution: Articles written for technical not grammatical accuracy, If poor grammar offends you proceed with caution ;-)

This simple little usefull script can be used to create a portgroup at the cluster level.  This enables you to create it once and have it be consistently deployed to all the ESX and/or ESXi hosts in your cluster.

foreach ($ESXhost in get-cluster CLUSTER_NAME| get-vmhost)


                                get-virtualswitch -vmhost $ESXhost -name VSWITCH| new-virtualportgroup -name PORTGROUP_NAME -vlanid VLANID



Simply replace CLUSTER_NAME with the name of your cluster, VSWITCH with the name of the vSwitch you would like to create the portgroup on, PORTGROUP_NAME wiht the name of your new portgroup, and VLANID on the VLAN you would like to associate with the portgroup.  If you do not wish to use a VLAN remove the -vlanid VLANID portion of the script.

One Reply to “VI Toolkit powershell simple script #1 – Create new portgroup”

  1. Bit pedantic but I think

    Get-Cluster -Name CLUSTER_NAME |
    Get-VMHost | Get-VirtualSwitch -Name VSWITCH |
    New-VirtualPortGroup -Name PORTGROUP_NAME -VLanId VLANID

    is neater as it avoids naming things you dont need to.

Leave a Reply