mc1903cae
Enthusiast
Enthusiast

New-VDPortgroup : Operation is not valid due to the current state of the object.

I am getting the following error when adding new port groups to an existing vDS.

New-VDPortgroup : Operation is not valid due to the current state of the object.

At P:\VMware\Create vDS PortGroups\Create vDS PortGroups - New v2.ps1:30 char:25

+ ... t-VDSwitch $vDS | New-VDPortgroup -Name $vDS_PGName -VlanId $vDS_VLAN

+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VDPortgroup], InvalidOperationException

    + FullyQualifiedErrorId : System.InvalidOperationException,VMware.VimAutomation.Vds.Commands.Cmdlets.NewVDPortgroup

The new port groups ARE added despite the error.

The Powershell script I am using is as follows:

# vCenter Credentials

$VIServer = "mc-vcsa-v-301a.momusconsulting.com"

$VIUsername = 'administrator@vsphere.local'

$VIPassword = 'Pa55word5!'

# The vDS to add the PortGroups to

$vDS = "vDS1_SiteA-65"

# vCenter vDS Port Group and VLAN - "{PGName}" = "{VLAN ID}"

$vDS_VLAN_PGNAME = @{

"VLAN050_Prod-VMs-A" = "50"

"VLAN101_Management-A" = "101"

"VLAN102_vMotion-A" = "102"

"VLAN103_vSAN-A" = "103"

"VLAN104_iSCSI1-A" = "104"

"VLAN105_iSCSI2-A" = "105"

"VLAN106_Replication-A" = "106"

"VLAN107_NFS-A" = "107"

}

Clear

vCenter = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue

$vDS_VLAN_PGNAME.GetEnumerator() | Sort-Object -Property Name | Foreach-Object {

    $vDS_PGName = $_.Name

    $vDS_VLAN = $_.Value

    

    Get-VDSwitch $vDS | New-VDPortgroup -Name $vDS_PGName -VlanId $vDS_VLAN

}

A bit confused. Would appreciate it if anyone can shine a light on why this is erroring.

Thanks,

M

T180985
Expert
Expert

You might want to edit out those credentials!

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
Reply
0 Kudos
mc1903cae
Enthusiast
Enthusiast

Thank you. No worries, it is an isolated test lab.

Reply
0 Kudos
LucD
Leadership
Leadership

Did you stop/start your PS/PowerCLI session between trials?


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

View solution in original post

Reply
0 Kudos
mc1903cae
Enthusiast
Enthusiast

Hi Luc,

Thank you. I hadn't tried closing and reopening my PS session. I have now and I no longer get the error!

What had I done/not done/missed? Still a bit confused.!

M

pastedImage_0.png

LucD
Leadership
Leadership

You didn't do anything wrong.

PS and/or PowerCLI sometimes get garbage in the objects they keep in memory.
That message you got is in a lot of the cases by such a mishap.
A stop/start of the session lets you start afresh.


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

Reply
0 Kudos
mc1903cae
Enthusiast
Enthusiast

Thank you for the explanation Luc.

Much appreciated.

M

Reply
0 Kudos