Question

I copied this example (example 5) from https://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/Set-NetworkAdapter.html and modified slightly for my own use but it's throwing an error:

Get-VM SDBNAPPQA03 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "10.30.88.0/21(VL712)" -Confirm:$false

Set-NetworkAdapter : 7/2/2013 8:07:05 AM    Set-NetworkAdapter        Object reference not set to an instance of an object.
At line:1 char:43
+ Get-VM SDBNAPPQA03 | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "10.30 ...
+                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

I'm getting an Adapter object back from Get-NetworkAdapter:

Get-VM SDBNAPPQA03 | Get-NetworkAdapter  | Get-Member


   TypeName: VMware.VimAutomation.ViCore.Impl.V1.VirtualDevice.NetworkAdapterImpl

Name             MemberType Definition
----             ---------- ----------
ConvertToVersion Method     T VersionedObjectInterop.ConvertToVersion[T]()
Equals           Method     bool Equals(System.Object obj)
GetHashCode      Method     int GetHashCode()
GetType          Method     type GetType()
IsConvertableTo  Method     bool VersionedObjectInterop.IsConvertableTo(type type)
LockUpdates      Method     void ExtensionData.LockUpdates()
ToString         Method     string ToString()
UnlockUpdates    Method     void ExtensionData.UnlockUpdates()
Client           Property   VMware.VimAutomation.ViCore.Interop.V1.VIAutomation Client {get;}
ConnectionState  Property    VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.ConnectInfo ConnectionState {get;}
ExtensionData    Property   System.Object ExtensionData {get;}
Id               Property   string Id {get;}
MacAddress       Property   string MacAddress {get;}
Name             Property   string Name {get;}
NetworkName      Property   string NetworkName {get;}
Parent           Property   VMware.VimAutomation.Sdk.Types.V1.VIObject Parent {get;}
ParentId         Property   string ParentId {get;}
Type             Property   VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.VirtualNetworkAdapterType Type {get;}
Uid              Property   string Uid {get;}
WakeOnLanEnabled Property   bool WakeOnLanEnabled {get;}

I can set the network name in the vCenter console without any problem.

I also tried the following command with the same result:

(Get-VM SDBNAPPQA03).Guest.Nics.Device | Set-NetworkAdapter -NetworkName "10.30.88.0/21(VL712)" -Confirm:$False

I have confirmed the network name is correct from the vCenter dropdown list for this VM. And I have tried other choices from the list.

Any ideas on how to set the NetworkAdapter?

Was it helpful?

Solution

It turns out the problem was not an exact match on the -NetworkName variable. It must be exact, including case. e.g.: I was feeding it "10.30.80.0/21(VL712)" but there is supposed to be a space before the left parenthesis to match the actual network name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top