Automation

 View Only
  • 1.  Script to copy port groups

    Posted Dec 11, 2018 09:44 PM

    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...



  • 2.  RE: Script to copy port groups

    Posted Dec 11, 2018 09:47 PM

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



  • 3.  RE: Script to copy port groups

    Posted Dec 12, 2018 12:28 AM

    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 .



  • 4.  RE: Script to copy port groups
    Best Answer

    Posted Dec 12, 2018 06:14 AM

    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

    }



  • 5.  RE: Script to copy port groups

    Posted Apr 07, 2021 07:09 AM

    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 |