本文介绍命令的 Get-VMNetworkAdapter
输出不包含与指定适配器关联的 IP 地址的问题。
适用于: Windows Server(所有版本)
现象
在虚拟机上的命令提示符处运行 Get-VMNetworkAdapter PowerShell 命令。 例如,运行以下命令:
PS C:\> Get-VMNetworkAdapter -VMName clu3vm1
命令输出如下所示:
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False CLU3VM1 Public 00155D081704 {Ok} {}
表的列不是包含预期的数据, IPAddress 而是为空。
若要解决此问题,请首先验证是否已启用键值对 Exchange Integration Service。 为此,请运行以下命令:
PS C:\> (Get-VM -VMName clu3vm1).VMIntegrationService
VMName Name Enabled PrimaryStatusDescription SecondaryStatusDescription
------ ---- ------- ------------------------ --------------------------
CLU3VM1 Guest Service Interface False OK
CLU3VM1 Heartbeat True OK OK
CLU3VM1 Key-Value Pair Exchange True OK
CLU3VM1 Shutdown True OK
CLU3VM1 Time Synchronization True OK
CLU3VM1 VSS True OK
如果未启用键值对 Exchange 服务,请启用它,然后再次运行 Get-VMNetworkAdapter
。 如果 IP 地址信息仍然缺失,并且已启用该服务, NetTCPIP
则虚拟机中可能缺少 WMI 提供程序。 在命令提示符处,在Get-WmiObject
Root\\Standardcimv2
命名空间上运行命令,如下所示:
PS C:\> Get-WmiObject -Namespace "root\standardcimv2" -Class __Win32Provider | select __NAMESPACE, Name
输出类似于以下示例。 请注意, ROOT\Standardcimv2 NetTCPIP
缺少。
__NAMESPACE Name
----------- ----
ROOT\Standardcimv2 NetEventPacketCapture
ROOT\Standardcimv2 MSFT_Printer
ROOT\Standardcimv2 NetTtCim
ROOT\Standardcimv2 MsNetImPlatform
ROOT\Standardcimv2 NetDaCim
ROOT\Standardcimv2 NlmCim
ROOT\Standardcimv2 netnat
ROOT\Standardcimv2 wfascim
ROOT\Standardcimv2 NetSwitchTeam
ROOT\Standardcimv2 NetAdapterCim
ROOT\Standardcimv2 dnsclientcim
ROOT\Standardcimv2 NetQosCim
ROOT\Standardcimv2 NetPeerDist
ROOT\Standardcimv2 NetNcCim
此外,用于 Get-WmiObject
查看类的属性 MSFT_NetIPInterfaceAdapter ,如下所示:
PS C:\> Get-WmiObject -Namespace "root\standardcimv2" -Class "MSFT_NetIPInterfaceAdapter"
输出类似于以下示例,而不是预期的响应:
Get-WmiObject : Invalid class "MSFT_NetIPInterfaceAdapter"
At line:1 char:1
+ Get-WmiObject -Namespace "root\Standardcimv2" -Class "MSFT_NetIPInter ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
原因
NetTCPIP WMI 提供程序未安装在来宾操作系统(虚拟机)中。
解决方法
在虚拟机上,打开提升的命令提示符窗口,然后更改为 %SystemRoot%\System32\wbem 文件夹。 在命令提示符处运行以下命令:
C:\Windows\System32\wbem>regsvr32.exe NetTCPIP.dll
C:\Windows\System32\wbem>mofcomp.exe NetTCPIP.mof
应会看到以下输出:
Microsoft (R) MOF Compiler Version 10.0.14393.0
Copyright (c) Microsoft Corp. 1997-2006. All rights reserved.
Parsing MOF file: NetTCPIP.mof
MOF file has been successfully parsed
Storing data in the repository...
Done!