PowerNSX | Create Logical Switches in bulk

Let's create multiple Logical switches in bulk with PowerNSX.

Simply copy below script and paste in your Powershell(I prefer Powershell ISE) console.

#Start here
$NSXManagerIP = "IP Address" #Mention NSX Manager IP address here in quote(")
$VCenterIP = "IP Address" #Mention vCenter Server IP address here in quote (")
$NSXManagerUser = "admin" #NSX manager admin username goes here
$NSXManagerPassword = "Password" #NSX manager admin password goes here
$VCenterUser = "administrator@vsphere.local" #Write down vCenter server admin username
$VCenterPassword = "VCenterPassword" #vCenter server admin password goes here

#Give the path of csv file containing name of all logical switches
$NSXLOGICALSWITCHFILE = import-csv C:\work\NSX_PowerNSX\Logical_Switch_Creation.csv

#Connect NSX Manager with below command
Connect-NsxServer -Server $NSXManagerIP -Username $NSXManagerUser -Password $NSXManagerPassword -ViUserName $VCenterUser -ViPassword $VCenterPassword

$LS = 0

#apply the loop here to create the number of logical switches equivalent to the number of LS names mentioned in above csv file
foreach ($LogicalSwitch in $NSXLOGICALSWITCHFILE)
## Creates Logical Switches for NSX. Possible Control Plane Modes are UNICAST_MODE,HYBRID_MODE,MULTICAST_MODE
Get-NsxTransportZone | New-NsxLogicalSwitch -Name $LogicalSwitch.LogicalSwitchName -ControlPlaneMode UNICAST_MODE

Write-Progress -Activity "Creating Logical Switches" -status "Created: $LS of $($NSXLOGICALSWITCHFILE.Count)" -PercentComplete (($LS / $NSXLOGICALSWITCHFILE.Count) * 100)


Write-Host "!!!All Logical Switches Created Sucsessfully" -ForegroundColor Green

#End here


Post a Comment