In this post you’ll find two Powershell one-liners to do some maintenance on Virtual Switches and PortGroups.
The first one-liner is inspired by Hany Michel his post: vMotion vs. VMotion .. Vote for your favorite! In this post he starts the debate about which name it should be. I voted for the “new” name vMotion. If you want to change the name of the VMotion portgroups to the “new” standard. You can do this by hand but why, we got PowerCLI 😉 The following one-liner will do the job:
Get-VMhost | % { Get-VirtualPortGroup -VMhost $_ -Name VMotion ` | Set-VirtualPortGroup -Name vMotion -Confirm:$false }
The vSwitches with the VMotion Protgroup name will be changed to vMotion:
The next one-liner will change the number of ports on vSwitch0. The default setting on vSwitch0 is 24 ports.
With PowerCLI you can easily change this again with an one-liner. This one-liner will change the value to 120 ports:
Get-VMHost | % {Get-VirtualSwitch -VMHost $_ -Name vSwitch0 | ` where {$_.NumPorts -lt "128"}} | ` % { Set-VirtualSwitch -VirtualSwitch $_ -NumPorts "128" }
You’ll see the following output:
You need to reboot the ESX host to apply the new setting.
One thought on “PowerCLI: Two Virtual Switch and Portgroup one-liners”