Wednesday, January 16, 2013

Adding a new portgroup to vSwitch using PowerCLI

This time I will present a very short powercli that I use to mass change ESXi hosts vSwitches. First, it retrieves a specific cluster, then all hosts in the cluster and for each host it starts configuration. There are 2 vSwitches on each host. Next, on each vSwitch it creates a new portgroup, it retrieves teaming policy, disables inherit failover and reverses the active and stanby vmnics. 

get-cluster CLTEST01 | get-vmhost | foreach {
get-virtualswitch -VMHost $_ -Name vSwitch0 | New-VirtualPortGroup -Name pg_QLF_A_91 -VLanID 91 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -InheritFailoverOrder:$false | Set-NicTeamingPolicy -MakeNicActive vmnic1 -MakeNicStandby vmnic0
get-virtualswitch -VMHost $_ -Name vSwitch1 | New-VirtualPortGroup -Name pg_QLF_I_92 -VLanID 92 | Get-NicTeamingPolicy | Set-NicTeamingPolicy -InheritFailoverOrder:$false | Set-NicTeamingPolicy -MakeNicActive vmnic3 -MakeNicStandby vmnic2
}

What I really enjoyed is the simplicity of PowerCLI.

1 comment:

Unknown said...

Thank you Razz ... like you said .. That was easy
Great Post