If you need to set any other information for your port group such as amending the active or standy nics you can use the script below.
I have done it per cluster but you can use any Get-VMHost command you want to get the hosts you want to apply the change to.
This adds a portgroup called vdi3 on vSwitch0 on vlan 500 to all hosts in cluster HP_BL460C_VDI3 and also sets vmnic0 to active and vmnic1 to standby
#Add and configure Port group to all hosts in a cluster Get-Cluster "HP_BL460C_VDI3" | Get-VMHost | Sort Name | %{ $vSwitch0 = $_ | Get-VirtualSwitch | where {$_.Name -like "vSwitch0"} $vSwitch0 | New-VirtualPortGroup -Name "vdi3" -vlanid 500 $VMPortGroup = $vSwitch0 | Get-VirtualPortGroup | Where-Object {$_.Name -eq "vdi3"} $VMPortGroup | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive "vmnic0" $VMPortGroup | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicStandby "vmnic1" $VMPortGroup | Get-NicTeamingPolicy | Set-NicTeamingPolicy -InheritFailoverOrder $false -InheritFailback $true -InheritLoadBalancingPolicy $true -InheritNetworkFailoverDetectionPolicy $true -InheritNotifySwitches $true }
When I try to run this in VESI I get the following :
Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At :line:34 char:35
+ $VMs = get-vm -Location (Get-Folder <<<< $VMFolder)
The Get-VM command in this example is getting all VMs in a particular VM folder (The blue folders) in VC. The VM Folder to search is in the following variable.
$VMFolder = "Workstations"
If you don't have a folder named "Workstations" it will fail.
If you don't need to run the script against a particular folder you can just return all VMs with:
$VMs = get-vm
Give that a try and see if you havemore luck.