VMware Cloud Community
iaindickason
Contributor
Contributor
Jump to solution

Set-NetworkAdapter returning 'Operation is not valid due to the current state of the object'

I'm using Set-Network Adapter to fix-up guest servers when a portgroup is renamed.  The request seems to make the required changes then crashses.  In vCenter I don't see any errors in the Recent Tasks list.

I am using the following code:

Get-VMHost vmware.host | Get-VM | Get-NetworkAdapter | Where {$_.NetworkName -eq "old_name"} |  Set-NetworkAdapter -NetworkName "new_name"-Confirm:$false
The error is:
Set-NetworkAdapter : 17/10/2012 12:16:56 p.m.    Set-NetworkAdapter        Operation is not valid due to the current
state of the object.
At line:1 char:114
+ ... old_name"} |  Set-NetworkAdapter -NetworkName "new_name" -Confirm:$false
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.
   SetNetworkAdapter
This is using PowerCLI 5.1 Release 1 against vCenter 5.0 and ESXi 5.0.
Any ideas how to either find out more about why it's failing or fix it.
Thanks
Iain
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No, that shouldn't be a problem.

Are you by any chance using PowerGui ?

There have been mentions of the exact same message when using an older version of PowerGui and the PowerPack.

See New-VM error (Operation is not valid due to the current state of the object.)


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Can you check the state of the NIC ?

Have a look at all the properties on the object returned by

Get-VMHost vmware.host | Get-VM | Get-NetworkAdapter | Where {$_.NetworkName -eq "old_name"}

I suspect there might be a VM with a NIC in a funny state


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

0 Kudos
iaindickason
Contributor
Contributor
Jump to solution

Hi LucD,

Looking at the returned data it all looks fine.  I've now run it individualy on 4 different guests on that cluster and also 3 guests on a ESXi 4.0 server with the same result.

Could it be an issue with me using PowerCLI 5.1 against a 5.0 vCenter?

Thanks

Iain

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that shouldn't be a problem.

Are you by any chance using PowerGui ?

There have been mentions of the exact same message when using an older version of PowerGui and the PowerPack.

See New-VM error (Operation is not valid due to the current state of the object.)


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

0 Kudos
iaindickason
Contributor
Contributor
Jump to solution

I have PowerGUI installed (current version 3.2.0.2237) but I'm using a seperate PowerCLI prompt to do my testing.  I have just tested it with PowerGUI closed and the issue still exists. I then un-installed PowerGUI and the issue existed in the PowerCLI prompt I already had open, but when I launched a new prompt the issues wasn't present.  Either PowerGUI was the caused of the issue or the prompt shell that was open, I suspect PowerGUI based on the previous reported issue.

I had better look for a new editor.

Thanks

Iain

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Before you decide to throw away PowerGui, you could check if the PowerPack is causing the problem.


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

0 Kudos
maishsk
Expert
Expert
Jump to solution

Just came across the same problem - no powerpack / PowerGUI being used...

Here is the output from the command

VERBOSE: 31/12/2012 12:12:18 Set-NetworkAdapter Started execution
VERBOSE: Performing operation "Setting NetworkName: CA-VLAN32" on Target "Network adapter 1".
VERBOSE: 31/12/2012 12:12:19 Set-NetworkAdapter Finished execution
Set-NetworkAdapter : 31/12/2012 12:12:19    Set-NetworkAdapter        Operation is not valid due to the current state
of the object.
At line:2 char:1
+ Set-NetworkAdapter -NetworkAdapter $_ -NetworkName $portgroup1 -Confirm:$false - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.
   SetNetworkAdapter
VERBOSE: 31/12/2012 12:12:19 Set-NetworkAdapter Started execution
VERBOSE: Performing operation "Setting NetworkName: CA-VLAN32" on Target "Network adapter 1".
VERBOSE: 31/12/2012 12:12:20 Set-NetworkAdapter Finished execution
Set-NetworkAdapter : 31/12/2012 12:12:20    Set-NetworkAdapter        Operation is not valid due to the current state
of the object.
At line:2 char:1
+ Set-NetworkAdapter -NetworkAdapter $_ -NetworkName $portgroup1 -Confirm:$false - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.
   SetNetworkAdapter
The setting sticks - but error is still thrown.
Any ideas?
Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
maishsk
Expert
Expert
Jump to solution

Just noticed this thread http://communities.vmware.com/thread/425459 and yes I am using v3 of Powershell

[12:14:06] ~> $PSVersionTable
Name                           Value
----                           -----
WSManStackVersion              3.0
PSCompatibleVersions           {1.0, 2.0, 3.0}
SerializationVersion           1.1.0.1
BuildVersion                   6.2.9200.16398
PSVersion                      3.0
CLRVersion                     4.0.30319.269
PSRemotingProtocolVersion      2.2
Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you still have a client with PS v2 somewhere ?

Curious to know if this is also a PS v3 feature.


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

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you have PowerShell v3 installed you can still start PowerShell v2 with:

PowerShell -version 2

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
maishsk
Expert
Expert
Jump to solution

From a different machine running

PS C:\Users\Administrator> $PSVersionTable
Name                           Value
----                           -----
CLRVersion                     2.0.50727.5466
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

Command completes successfully...

And by feature - do you mean bug ???

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Well, you can't file a bug for something that is not supported, now can you Smiley Wink


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

0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Thanks for raising this, we of course want to know of any issues you hit in PS3 via these communities to help us provide support in the future.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
maishsk
Expert
Expert
Jump to solution

Ran into the same thing again today - (which is strange becuase this was working - but all of a sudden it stopped today) with the New-Harddisk cmdlet.

with powershell -version 2 it works fine..

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos