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.