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

bbo*_*ler 4 powershell windows-10

如何对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
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

我正在尝试将 Docker 用于 Windows 10(曾经可以工作),但 PowerShell 故障导致 Docker 无法启动(GitHub 问题)。错误发生在我的主机上,而不是在 Docker 容器内。为了这个问题你应该忽略Docker的细节,只是由于这个问题我不能使用Docker。

bbo*_*ler 8

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

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

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

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

  2. 重新启用 WMI 服务

sc 配置 winmgmt start= 自动

  1. 重新启动机器。

如果上述方法无效的尝试chkdsksfcdism。此外,您可以尝试Windows 修复安装