VMware Cloud Community
Gaprofitt17
Enthusiast
Enthusiast
Jump to solution

Script to copy port groups

Hi All,

I need help, I've created a new vDS called dvSwitch3.  I want to copy the port groups from say dvSwitch01 to dvSwitch03.  How do I accomplish this?  I want to leave
the portgroups in place on both switches...

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

But note that this a very limited copy of the settings of the portgroups.
The VLANId for example is not copied.

Currently it only does the LoadBalancing and Teaming order.

Also note that the script assumes the number of Uplinks on both VDS is the same and the standard Uplink naming was used.

This due to the Active and Standby settings being copied.

If need be, other portgroup properties could be copied as well.

$oldVds = 'dvSwitch01 '

$newVds = 'dvSwitch03'

$newVds = Get-VDSwitch -Name $newVds

Get-VDSwitch -Name $oldVds |

Get-VDPortgroup |

where{-not $_.IsUplink} |

ForEach-Object -Process {

    $teaming = Get-VDUplinkTeamingPolicy -VDPortgroup $_

    $sTeam = @{

        LoadBalancingPolicy = $teaming.LoadBalancingPolicy

        Confirm = $false   

    }

    if($teaming.ActiveUplinkPort){

        $sTeam.Add('ActiveUplinkPort',$teaming.ActiveUplinkPort)

    }

    if($teaming.StandbyUplinkPort){

        $sTeam.Add('StandbyUplinkPort',$teaming.StandbyUplinkPort)

    }

    New-VDPortgroup -Name "$($_.Name)_dv03-portgroup" -VDSwitch $newVds -Confirm:$false |

    Get-VDUplinkTeamingPolicy |

    Set-VDUplinkTeamingPolicy @sTeam

}


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

Is that just creating the portgroups with the same name?
Or do specific settings need to be copied along?


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

Reply
0 Kudos
Gaprofitt17
Enthusiast
Enthusiast
Jump to solution

If I recall portgroups have to be unique by vCenter right? If so If I could append say dv03-portgroup name on the new switch that would be good.  A bonus would be setting the teaming policy to load based.

Thanks .

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

But note that this a very limited copy of the settings of the portgroups.
The VLANId for example is not copied.

Currently it only does the LoadBalancing and Teaming order.

Also note that the script assumes the number of Uplinks on both VDS is the same and the standard Uplink naming was used.

This due to the Active and Standby settings being copied.

If need be, other portgroup properties could be copied as well.

$oldVds = 'dvSwitch01 '

$newVds = 'dvSwitch03'

$newVds = Get-VDSwitch -Name $newVds

Get-VDSwitch -Name $oldVds |

Get-VDPortgroup |

where{-not $_.IsUplink} |

ForEach-Object -Process {

    $teaming = Get-VDUplinkTeamingPolicy -VDPortgroup $_

    $sTeam = @{

        LoadBalancingPolicy = $teaming.LoadBalancingPolicy

        Confirm = $false   

    }

    if($teaming.ActiveUplinkPort){

        $sTeam.Add('ActiveUplinkPort',$teaming.ActiveUplinkPort)

    }

    if($teaming.StandbyUplinkPort){

        $sTeam.Add('StandbyUplinkPort',$teaming.StandbyUplinkPort)

    }

    New-VDPortgroup -Name "$($_.Name)_dv03-portgroup" -VDSwitch $newVds -Confirm:$false |

    Get-VDUplinkTeamingPolicy |

    Set-VDUplinkTeamingPolicy @sTeam

}


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

Reply
0 Kudos
Mattie84
Contributor
Contributor
Jump to solution

Ran into this script, as i needed it. I also needed to copy the VLAN ID, so i  adjusted the script a little bit and wanted to share it with you:

Add /replace the section:

replace the line:

"New-VDPortgroup -Name "$($_.Name)_dv03-portgroup" -VDSwitch $newVds -Confirm:$false |"

with:

$a = ($_).VlanConfiguration.VlanId

New-VDPortgroup -Name "$($_.Name)_dv03-portgroup" -vlanid $a -VDSwitch $newVds -Confirm:$false |

Reply
0 Kudos