Hi
I was wondering if anybody had a script to add new port groups to dvswitches
I want to be able to import a csv with the new port group names and VLAN's and have it apply to a dvswitch by the name of the switch which they need to be created on. With the port-group security setting and teaming & failover defined within the script
am sure someone would have written something like this already? Maybe Luc
Cheers
With the New-VDPortgroup cmdlet this shouldn't be too difficult.
Something along these lines perhaps
Import-Csv C:\dvportgroup.csv -UseCulture | %{
$dvSw = Get-VDSwitch -Name $_.dvSw
New-VDPortgroup -VDSwitch $dvSw -Name $_.dvPg -VlanId $_.VlanId -Confirm:$false
}
and your CSV should have the following layout
"dvSw","dvPg","VlanId"
"sw1","pg1","123"
"sw2","pg2","456"
Note that the sample script is minimal, you probably want to use some other parameters on the New-VDPortgroup cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
thanks for getting back so quick
yeah i would want to configure port group setting
Security - Promiscuous Mode: Reject; MAC Address Changes: Reject; Forged Transmits: Reject
Teaming and Failover - Load Balancing: Route based on physical NIC load; Network Failover Detection: Link status only; Notify Switches: Yes; Failback: Yes
and also to run against a number of dvSwitches maybe a prompt to enter in dvswitch names that i would need it to run against?
thanks for you help
Why would you want to prompt for a dvSwitch name, while you can have this in the CSV file as well.
I would go for 100% automation :smileygrin:
Several of the PG settings you require are not present on the cmdlet.
But could you perhaps consider using the ReferencePortgroup parameter ?
That way you only need to configure this portgroup, and all others will take their settings from it.
Note that this requires vSphere 5.1 !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
that is a shame. It appears the dvswitch are less scriptible than the standard switches which doesn't make much sense to me. You would think that as its an enterprise plus feature that it would have been easy to script from mass deployments . What happens when you have hundreds of port groups to configure in a new deployment? At least with the standard switch it could be scripted, you might have had to ran it against very host but once it was scripted that was easy to do
I like the idea to using a reference port group but we haven't upgraded to 5.1 yet so that wont help at the moment
Thanks for you help again
Until the PowerCLI Dev Team expands the features of the New-VDPortgroup (and Set-VDPortgroup) cmdlet, you could have a look at my New-dvSwPortgroup function in dvSwitch scripting – Part 2 – dvPortgroup. It provides parameters to set up some of the requirements you mentioned.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc
could you please give me an example of how i would use the function to create new port group against a number of dvswitches with the teaming and security set up the way I need it
Cheers
Sure, just copy the New-dvSwPortgroup function to a .ps1 file.
After the function, add the following lines
$dvSw = Get-VDSwitch -Name YourdvSwName
New-dvSwPortgroup -dvSw $dvSw.ExtensionData -PgName YourNewPG `
-SecPolPromiciousMode:$false -SecPolMacChanges:$false -SecPolForgedTransmits:$false `
-TeamingPolicy "loadbalance_loadbased" `
-TeamingNotifySwitches:$true -TeamingRollingOrder:$false
And if you want to feed this from a CSV file, you can do something like this
Import-Csv C:\new-dvpg.csv -UseCulture | %{
$dvSw = Get-VDSwitch -Name $_.dvSwName
New-dvSwPortgroup -dvSw $dvSw.ExtensionData -PgName $_.dvPgName `
-SecPolPromiciousMode:$false -SecPolMacChanges:$false -SecPolForgedTransmits:$false `
-TeamingPolicy "loadbalance_loadbased" `
-TeamingNotifySwitches:$true -TeamingRollingOrder:$false
}
This assumes your CSV file looks like this
"dvSwName","dvPgName"
"dvsw1","dvpg1"
"dvsw1","dvpg2"
"dvsw1","dvpg4"
"dvsw2","dvpg2"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference