This will work for a standard switch and only if a vswitch is already configured.
If you want to create the vSwitch first, check this post >http://www.pcli.me/?p=28

###Edit the four vars and paste the script.

$thecluster = “MyCluster”
$vswitch = “vSwitch1”
$PG = “MyProdNetwork”
$vlan = “1337”

$thehosts = get-cluster $thecluster | get-vmhost | %{$_.name}
foreach($ahost in $thehosts){
New-VirtualPortGroup -VirtualSwitch ( Get-VirtualSwitch -Name $vswitch -VMHost $ahost ) -Name $PG -VLanId $vlan
}

##########################################

If you need the portgroup to contain a vmKernel for vmotion, use the following instead:
#######  Set the four cluster vars then the hash table for the different vmkernel IP addresses
$thecluster = “MyCluster”
$vswitch = “vSwitch1”
$PG = “vmotion0”
$vlan = “0”

####### Create the vmk IP hashtable #######

$myvmkips = @{}
$myvmkips.add(“host1.pcli.me”,”10.10.10.10″)
$myvmkips.add(“host2.pcli.me”,”10.10.10.11″)
.
.
.
$myvmkips.add(“host9.pcli.me”,”10.10.10.19″)
####### end hashtable #######

 

$thehosts = get-cluster $thecluster | get-vmhost | %{$_.name}
foreach($ahost in $thehosts){
New-VirtualPortGroup -VirtualSwitch ( Get-VirtualSwitch -Name $vswitch -VMHost $ahost ) -Name $PG -VLanId $vlan
$vmkip = $myvmkips.get_item(“ahost”)
New-VMHostNetworkAdapter -VMHost $ahost -VirtualSwitch $vswitch -PortGroup $PG” -IP $vmkip -SubnetMask 255.255.255.0 -VMotionEnabled $true -Confirm:$false
}

 

Vmware Links:
VirtualPortGroup – http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-VirtualPortGroup.html
VMHostNetworkAdapter = http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/New-VMHostNetworkAdapter.html

This will enable vmotion on an existing vmkernel portgroup for all hosts in a cluster.
If you want to create the port group first, check this post > http://www.pcli.me/?p=16

$ClusterName = “MyCluster”
$MyPortGroup = “MyPortGroup”
get-cluster $ClusterName | Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | where {$_.PortGroupName -eq $MyPortGroup} | Set-VMHostNetworkAdapter -VMotionEnabled $true -Confirm:$false

This runs slow and you cannot use a “-RunAsync” to make it faster.

Vmware Link:
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VMHostNetworkAdapter.html