You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行Get-DscConfigurationStatus报错Invalid namespace,DSC版本配置求助

PowerShell DSC "Invalid namespace" 错误排查与解决

执行Get-DscConfigurationStatus时遭遇如下错误:

PS C:\windows\system32> Get-DscConfigurationStatus
Get-DscConfigurationStatus : Invalid namespace 
At line:1 char:1
+ Get-DscConfigurationStatus
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (MSFT_DSCLocalConfigurationManager:root/Microsoft/...gurationManager) [Get-DscConfigurationSt 
   atus], CimException
    + FullyQualifiedErrorId : HRESULT 0x8004100e,Get-DscConfigurationStatus

问题根源

这个错误核心是WMI命名空间root/Microsoft/Windows/DesiredStateConfiguration损坏或未正确注册,和你提到的版本冲突直接相关:

  • PowerShell ISE默认使用的PowerShell 5.1,自带的PSDesiredStateConfiguration 1.1属于传统DSC,依赖WMI命名空间运行
  • PowerShell 7适配的PSDesiredStateConfiguration 2.x是DSCv2,基于CIM实现,和传统DSC的WMI命名空间不兼容
  • 强制在PowerShell 5.1环境中安装2.x版本,会覆盖或破坏传统DSC的WMI组件,导致依赖该命名空间的命令失效

解决步骤

1. 清理冲突的模块版本

打开PowerShell ISE(确保是PowerShell 5.1环境),执行以下操作:

  • 卸载PSDesiredStateConfiguration 2.0.7版本:
    Uninstall-Module -Name PSDesiredStateConfiguration -RequiredVersion 2.0.7 -Force
    
  • 确认仅保留系统自带的1.1版本:
    Get-Module -Name PSDesiredStateConfiguration -ListAvailable
    
    正常输出应只显示版本1.1,路径为C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration

2. 修复WMI DSC命名空间

如果卸载后错误仍存在,需要重新注册DSC的WMI组件:
以管理员身份打开PowerShell 5.1,执行:

$dscNamespace = "root/Microsoft/Windows/DesiredStateConfiguration"
# 删除损坏的命名空间
Remove-WmiObject -Namespace root -Class __Namespace -Filter "Name='Microsoft/Windows/DesiredStateConfiguration'" -ErrorAction SilentlyContinue
# 重新注册DSC核心MOF文件
& "$env:windir\system32\wbem\mofcomp.exe" "$env:windir\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\MSFT_DSCLocalConfigurationManager.mof"

执行完成后,再次运行Get-DscConfigurationStatus验证是否恢复正常

3. 区分版本使用DSC

  • PowerShell 5.1(ISE):仅使用系统自带的PSDesiredStateConfiguration 1.1,搭配已安装的PSDscResources 2.12.0.0(两者兼容)
  • PowerShell 7:单独安装PSDesiredStateConfiguration 2.x,同时使用适配DSCv2的资源模块(避免混用传统DSC资源)
  • 禁止在同一个PowerShell版本环境中混合安装不同大版本的PSDesiredStateConfiguration

内容的提问来源于stack exchange,提问作者Ryan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 15:43:28