VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

create vswitch and virtualportgroup

trying to do a vswitch and portgroup creation with this but only working for firt host and errors out

$vsswitch = "vSwitch3"

$vmhosts = get-vmhost -Server vc

foreach ($vmhost in $vmhosts) {

New-VirtualSwitch -Name $vsswitch -VMHost $vmhost -NumPorts 256 -Confirm:$false

Import-Csv "C:\scripts\pgs.csv" -UseCulture | %{

$Name = $_.name

$id = $_.id

# create dvportgroups

New-VirtualPortGroup -VirtualSwitch $vsswitch -Name $Name -VlanId $id -Confirm:$false

}

}

any idea?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The New-VirtualPortgroup cmdlet doesn't accept OBN for the VirtualSwitch parameter.

Do it like this

$vmhosts = Get-VMHost -Server vc

foreach ($vmhost in $vmhosts) {

   $vss = New-VirtualSwitch -Name $vsswitch -VMHost $vmhost -NumPorts 256 -Confirm:$false

   Import-Csv "C:\scripts\pgs.csv" -UseCulture | % {

   $Name = $_.name

   $id = $_.id

   # create dvportgroups

   New-VirtualPortGroup -VirtualSwitch $vss -Name $Name -VlanId $id -Confirm:$false

   }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The New-VirtualPortgroup cmdlet doesn't accept OBN for the VirtualSwitch parameter.

Do it like this

$vmhosts = Get-VMHost -Server vc

foreach ($vmhost in $vmhosts) {

   $vss = New-VirtualSwitch -Name $vsswitch -VMHost $vmhost -NumPorts 256 -Confirm:$false

   Import-Csv "C:\scripts\pgs.csv" -UseCulture | % {

   $Name = $_.name

   $id = $_.id

   # create dvportgroups

   New-VirtualPortGroup -VirtualSwitch $vss -Name $Name -VlanId $id -Confirm:$false

   }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert
Jump to solution

Thank you

0 Kudos