Automation

 View Only
  • 1.  power cli to create distributed port group

    Posted Feb 07, 2018 01:22 AM

    can some one help me with a powercli command to create a distributed port group but i also need to select uplink 3 & 4 as active teaming and failover and uplink 1 & 2 as unused uplink

    or power cli comand to create a distributed port group by copying settings from another vlan but name and vlan ID i will provide. i need to create lot of vlan so any help to script it also is appreciated.

    esxi and vcenter 6.5 ui

    Below command will help if i can specify vlan id as well in comand. currently vlan ID its taking from ReferencePortgroup.

    $myReferncePortroup = Get-VDPortgroup -Name "MyReferencePortGroup"

    Get-VDSwitch -Name "MyVDSwitch" | New-VDPortgroup -Name "MyVDPortGroup" -ReferencePortgroup $myReferncePortroup



  • 2.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 05:44 AM

    You will have to use a Set-VDPortgroup to change the VlanId

    $myReferncePortroup = Get-VDPortgroup -Name "MyReferencePortGroup"

    $pg = Get-VDSwitch -Name "MyVDSwitch" |

    New-VDPortgroup -Name "MyVDPortGroup" -ReferencePortgroup $myReferncePortroup

    Set-VDPortgroup -VDPortgroup $pg -VlanId $vlanId -Confirm:$false



  • 3.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 07:54 PM

    Thanks Luc D

    if i need to create for 100 vlan, how the script will looks like and how do i give the input file with vlan name and vlan ID.



  • 4.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 08:00 PM

    Do you have that information available in a CSV file?

    Do you use the same ReferencePortGroup for all the new VDPortgroups?
    Are all VDPortgroups on the same VDSwitch?

    Ideally, that should be in a CSV file.
    Something similar to this

    VDPortgroup,VLANId,VDSwitch,VDReferencePortgroup

    pg1,100,vds1,pgRef1

    pg2,101,vds1,pgRef1

    pg3,102,vds2,pgRef2



  • 5.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 08:10 PM

    yes same reference group can be used and yes all VDPortgroups on the same VDSwitch



  • 6.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 08:06 PM

    can i create a csv file like below

    cluster,vSwitch,VLANname,VLANid

    Maintenance,Test01,test01,100

    save above as MyVLANs.csv

    ------

    Script like below

    -------

    $InputFile = .\MyVLANs.csv

    $MyVLANFile = Import-CSV $InputFile

    $myReferncePortroup = Get-VDPortgroup -Name "test01"

    ForEach ($VLAN in $MyVLANFile) {

    $MyCluster = $VLAN.cluster

    $MyvSwitch = $VLAN.vSwitch

    $MyVLANname = $VLAN.VLANname

    $MyVLANid = $VLAN.VLANid

    get-cluster $MyCluster  | Get-VDSwitch -Name $MyvSwitch |

    New-VDPortgroup -Name $MyVLANname -ReferencePortgroup $myReferncePortroup

    Set-VDPortgroup -VDPortgroup $pg -VlanId $MyVLANid -Confirm:$false

    }

    dose this work? if not can you give me a good one.



  • 7.  RE: power cli to create distributed port group
    Best Answer

    Posted Feb 07, 2018 08:12 PM

    Or even simpler, no intermediate variables, and all in one pipeline construct.

    $InputFile = .\MyVLANs.csv

    $MyVLANFile = Import-CSV $InputFile

    $myReferencePortroup = Get-VDPortgroup -Name "test01"

    ForEach ($VLAN in $MyVLANFile) {

        Get-Cluster -Name $VLAN.cluster  | Get-VDSwitch -Name $VLAN.vSwitch |

        New-VDPortgroup -Name $VLAN.VLANname -ReferencePortgroup $myReferencePortroup |

        Set-VDPortgroup -VlanId $VLAN.VLANid -Confirm:$false

    }



  • 8.  RE: power cli to create distributed port group

    Posted Feb 07, 2018 08:36 PM

    Thanks LucD your help is much appreciated.

    i just removed  get- cluster because it gave me below error.

    Get-VDSwitch : The input object cannot be bound to any parameters for the command either because the command does no

    take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

    At line:1 char:33

    + Get-Cluster -Name Maintenance | Get-VDSwitch TestSwitch

    +                                 ~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (Maintenance:PSObject) [Get-VDSwitch], ParameterBindingException

        + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.Vds.Commands.GetVDSwitch

    without that it worked fine since we have only one switch with same name in my env it was fine for me.

    ------------------------

    $MyVLANFile = Import-CSV .\MyVLANs.csv

    $myReferencePortroup = Get-VDPortgroup -Name "test01"

    ForEach ($VLAN in $MyVLANFile) {

        Get-VDSwitch -Name $VLAN.vSwitch |

        New-VDPortgroup -Name $VLAN.VLANname -ReferencePortgroup $myReferencePortroup |

        Set-VDPortgroup -VlanId $VLAN.VLANid -Confirm:$false

    }

    ------------------------

    Thanks again for your help.