Adding Virtual Networks
The following PowerCLI creates 3 Networks on server esxi1
$networks="SHIRE","RIVENDELL","GONDOR"
$esxi_host_name="esxi1.range.local"
$vcenter_server="vcenter.range.local"
Connect-VIServer -server $vcenter_server
$vmhost = Get-VMHost -Name $esxi_host_name
foreach($network in $networks)
{
try
{
$vswitch = New-VirtualSwitch -VMHost $vmhost -Name $network -ErrorAction Ignore
$vpg = New-VirtualPortGroup -VirtualSwitch $vswitch -Name $network
Write-Host "Created $network"
}
catch
{
Write-host -ForegroundColor Red "Count not create $$network on $esxi_host_name"
}
}