VMware Cloud Community
marre1
Contributor
Contributor
Jump to solution

Rename imported portgroups on distributed virtual switch

Hi,

I´ve imported a backup from one distributed virtual switch to a new one with another name. However all the imported portgroups gets a (0) suffix. Since  there are lots of portgroups I´d like remove the (0) suffix from the PGs on the dVswitch. Does anyone have a script for a similar operation?

Thanks,

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

And if you try like this?

$vdSwName = "vds1"

Get-VDSwitch -Name $vdSwName |
Get-VDPortgroup -PipelineVariable pg |
where{$_.Name -match "(0)$"} |
Foreach-Object -Process {
    Set-VDPortgroup -VDPortgroup $pg -Name ($pg.Name.TrimEnd('(0)')) -Confirm:$false
}


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vdSwName = vds1"

Get-VDSwitch -Name $vdSwName |
Get-VDPortgroup |
where{$_.Name -match "(0)$"} |
Set-VDPortgroup -Name ($_.Name.TrimEnd('(0)')) -Confirm:$false

 


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

Reply
0 Kudos
marre1
Contributor
Contributor
Jump to solution

Hi,

Thanks for your reply. However I get this error "You cannot call a method on a null-valued expression.".

The selections work but not the last set-vdportgroup part.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And if you try like this?

$vdSwName = "vds1"

Get-VDSwitch -Name $vdSwName |
Get-VDPortgroup -PipelineVariable pg |
where{$_.Name -match "(0)$"} |
Foreach-Object -Process {
    Set-VDPortgroup -VDPortgroup $pg -Name ($pg.Name.TrimEnd('(0)')) -Confirm:$false
}


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

Reply
0 Kudos
marre1
Contributor
Contributor
Jump to solution

That did the trick! Many thanks!

Reply
0 Kudos