Get-Net* PowerShell cmdlet 因类无效而失败

Get-Net* PowerShell cmdlet 因类无效而失败

如何排除故障并修复Get-Net*PowerShell cmdlet?以下所有操作均失败Invalid class。我使用的是 Windows 10 版本 1511,目前没有升级到 1607 的选项。

第一个 PowerShell 版本:

PS C:\WINDOWS\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  672

错误:

PS C:\WINDOWS\system32> Get-NetAdapter
Get-NetAdapter : Invalid class
At line:1 char:1
+ Get-NetAdapter
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetAdapter:ROOT/StandardCimv2/MSFT_NetAdapter) [Get-NetAdapter], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetAdapter

PS C:\WINDOWS\system32> Get-NetIPAddress
Get-NetIPAddress : Invalid class
At line:1 char:1
+ Get-NetIPAddress
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [Get-NetIPAddress], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetIPAddress

PS C:\WINDOWS\system32> Get-NetAdapterHardwareInfo
Get-NetAdapterHardwareInfo : Invalid class
At line:1 char:1
+ Get-NetAdapterHardwareInfo
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetAdapterHardwareInfoSettingData:ROOT/StandardCi...InfoSettingData
   ) [Get-NetAdapterHardwareInfo], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetAdapterHardwareInfo

PS C:\WINDOWS\system32> Get-NetAdapterBinding
Get-NetAdapterBinding : Invalid class
At line:1 char:1
+ Get-NetAdapterBinding
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetAdapterBindingSettingData:ROOT/StandardCi...dingSettingData) [Ge
   t-NetAdapterBinding], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetAdapterBinding

PS C:\WINDOWS\system32> Get-NetAdapterStatistics -Name "Wi-Fi"
Get-NetAdapterStatistics : Invalid class
At line:1 char:1
+ Get-NetAdapterStatistics -Name "Wi-Fi"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetAdapterStatisticsSettingData:ROOT/StandardCi...ticsSettingData)
   [Get-NetAdapterStatistics], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetAdapterStatistics

PS C:\WINDOWS\system32> Get-NetAdapterStatistics -Name "Ethernet"
Get-NetAdapterStatistics : Invalid class
At line:1 char:1
+ Get-NetAdapterStatistics -Name "Ethernet"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_NetAdapterStatisticsSettingData:ROOT/StandardCi...ticsSettingData)
   [Get-NetAdapterStatistics], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Get-NetAdapterStatistics

我正在尝试使用 Docker for Windows 10(以前可以正常工作),但 PowerShell 故障导致 Docker 无法启动(GitHub 问题)。错误发生在我的主机上,而不是 Docker 容器内。对于这个问题,您应该忽略 Docker 详细信息,只是由于这个问题我无法使用 Docker。

答案1

感谢Microsoft TechNet 论坛,我们可以看到 WMI 存储库已损坏,可以按如下方式修复:

  1. 禁用并停止 WMI 服务
sc config winmgmt start= disabled
net stop winmgmt
  1. 运行以下命令
 Winmgmt /salvagerepository %windir%\System32\wbem
 Winmgmt /resetrepository %windir%\System32\wbem
  1. 重新启用 WMI 服务并重新启动
 sc config winmgmt start= auto

如果问题仍然存在,请尝试以下步骤重建存储库:

  1. 禁用并停止 WMI 服务
 sc config winmgmt start= disabled     (note that there is a blank between '=' and 'disabled')
 net stop winmgmt
  1. 将存储库文件夹(位于%windir%\System32\wbem\repository)重命名为repository.old

  2. 重新启用 WMI 服务

sc config winmgmt start=自动

  1. 重新启动机器。

如果上述方法不起作用chkdsk,请尝试sfc, 和dism。此外,您还可以尝试Windows 修复安装

答案2

有些机器不理解 sc 命令。因此请尝试sc.exe使用sc命令。

sc.exe config winmgmt start= disabled

相关内容