Raducanu
Enthusiast
Enthusiast

Rename dvSwitch PortGroup

Hello,

i'm new the PowerShell and looking for a way to rename multiple portgroups on a distributed virtual switch.

Is there a "simple" way to fix a simple typing mistake?

Portgroup name is "XYZ-pubic" but should be "XYZ-public". XYZ is variable.

Thank you,

Marcel

Reply
0 Kudos
aravinds3107
Virtuoso
Virtuoso

Did you check these already?

http://communities.vmware.com/message/1475219#1475219

http://communities.vmware.com/message/1173158#1173158

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful |Blog: http://aravindsivaraman.com/ | Twitter : ss_aravind
Reply
0 Kudos
Raducanu
Enthusiast
Enthusiast

Hello,

thanks for the reply.

I know the command for changing the portgroup name.

But i hope that there is any posibility to replace the "pubic" to "public" (i think there must be a way with "foreachobject").

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this

$dvSw = Get-VirtualSwitch -Name MydvSw
$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
Get-View
$dvSw.ExtensionData.Portgroup | %{     if($_.Name -like "*-pubic"){         $spec.Name = $_.Name -replace 'pubic','public'
       
$spec.configVersion = $_.Config.ConfigVersion         $_.ReconfigureDVPortgroup($spec)     } }

Or if you want to do this for all your dvSwitches, you could do

$spec = New-Object VMware.Vim.DVPortgroupConfigSpec
Get-VirtualSwitch | %{
    Get-View $_.ExtensionData.Portgroup | %{
        if($_.Name -like "*-pubic"){
            $spec.Name = $_.Name -replace 'pubic','public'
            $spec.configVersion = $_.Config.ConfigVersion             $_.ReconfigureDVPortgroup($spec)         }     } }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference