Rename vswitch portgroups using PowerCli
Rename vswitch portgroups PowerCli – Here’s a quick and easy way to rename all port groups on a specific vSwitch on all hosts in a vSphere cluster using PowerCli.
Do remember to establish a connection to your vCenter server via the below powercli one liner.
Connect-VIServer -server <vCenter Server IP> -credential (Get-Credential)
The Below function accepts two parameters which comprises of a single vSphere cluster name and also the multiple values of the vSwitch name.
As you can make out from the function it extracts all the VMhosts from the vSphere cluster name, next for each of these hosts gets the standard virtual switch which match the input parameter vSwitch name to the cluster, next it gets the virtual port groups for the vswitch, and for each of them goes ahead and renames them with the required name, here in my example, i am adding a prefix “dr_” in front of the virtualportgroup name.
function RenamePortVSwitch ([String]$ClusterName,[String[]]$vSwitchName) { foreach ($vswitch in $vSwitchName) { Write-Host "" Write-Host "Renaming All PortGroups in $vswitch" -ForegroundColor Black -BackgroundColor Green Write-Host "" Get-Cluster $ClusterName | Get-VMHost | Get-VirtualSwitch -Standard -Name $vswitch | Get-VirtualPortGroup -Standard | %{Set-VirtualPortGroup -VirtualPortGroup $_ -Name "dr_$($_.name)"} Write-Host "" } }
To execute this function, just copy paste the above code to a powershell console, and invoke the function.
PowerCli Rocks!!
Just imagine how much time it would take you to perform this task manually on 8 node cluster with 8 hosts each :)?, maybe a week !
I hope you enjoyed this blogpost on “Rename vswitch portgroups using PowerCli” and found this information useful.
Be aware that this approach will remove all the non-inherited security, traffic shaping and teaming and failover settings on the port group. If you don’t want this to happen, use the UpdatePortGroup method instead.