【问题标题】:powercli set-networkadapter object reference not set to an instance of an objectpowercli set-networkadapter 对象引用未设置为对象的实例
【发布时间】:2013-07-02 15:22:55
【问题描述】:

我从 https://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/Set-NetworkAdapter.html 复制了这个示例(示例 5)并稍作修改以供我自己使用,但它抛出了一个错误:

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

我从 Get-NetworkAdapter 得到一个 Adapter 对象:

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;}

我可以在 vCenter 控制台中设置网络名称,没有任何问题。

我也尝试了以下命令,结果相同:

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

我已从该 VM 的 vCenter 下拉列表中确认网络名称正确。我已经尝试了列表中的其他选择。

关于如何设置 NetworkAdapter 的任何想法?

【问题讨论】:

    标签: vmware powercli


    【解决方案1】:

    事实证明,问题不是与 -NetworkName 变量完全匹配。必须准确,包括大小写。 例如:我输入的是“10.30.80.0/21(VL712)”,但左括号前应该有一个空格来匹配实际的网络名称。

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      相关资源
      最近更新 更多