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

如何无需重启停止Ansible发起的无响应Windows DSC操作?

无需重启终止挂起的Windows DSC操作的方法

1. 定位并终止DSC相关进程

DSC操作依赖WMI提供进程(wmiprvse.exe),可筛选关联DSC的实例并强制终止:

# 查找与DSC绑定的wmiprvse进程
Get-CimInstance Win32_Process | Where-Object {
    $_.Name -eq "wmiprvse.exe" -and $_.CommandLine -match "DSC"
} | Select-Object ProcessId, CommandLine

# 替换<ProcessId>为实际进程ID,强制终止
Stop-Process -Id <ProcessId> -Force -ErrorAction SilentlyContinue

若筛选不到目标进程,可结合进程父ID、运行上下文判断(注意:不要终止所有wmiprvse.exe,避免影响其他系统服务)。

2. 清理DSC锁定状态文件

DSC在C:\Windows\System32\Configuration目录下维护运行状态文件,挂起进程会锁定这些文件,执行备份并重命名操作:

# 备份并重命名锁定的核心状态文件
Rename-Item C:\Windows\System32\Configuration\DSCEngineCache.mof DSCEngineCache.mof.bak -Force
Rename-Item C:\Windows\System32\Configuration\Current.mof Current.mof.bak -Force
Rename-Item C:\Windows\System32\Configuration\MetaConfig.mof MetaConfig.mof.bak -Force

3. 重置DSC本地配置管理器(LCM)

通过重置LCM清除挂起的操作状态,之后可恢复原有配置:

# 创建临时重置LCM的配置
[DSCLocalConfigurationManager()]
configuration ResetLCM {
    Node localhost {
        Settings {
            RefreshMode = 'Disabled'
            ConfigurationMode = 'ApplyOnly'
        }
    }
}

# 生成并应用重置配置
ResetLCM
Set-DscLocalConfigurationManager -Path .\ResetLCM -Force

# 恢复原有LCM配置(根据实际环境调整参数)
[DSCLocalConfigurationManager()]
configuration RestoreLCM {
    Node localhost {
        Settings {
            RefreshMode = 'Push' # 替换为原有模式如Pull
            ConfigurationMode = 'ApplyAndMonitor' # 替换为原有模式
        }
    }
}
RestoreLCM
Set-DscLocalConfigurationManager -Path .\RestoreLCM -Force

4. 终止Ansible发起的关联进程

若Ansible在Windows上的执行进程仍停滞,直接终止:

# 查找Ansible或win_dsc相关进程
Get-Process | Where-Object {$_.Name -like "*ansible*" -or $_.CommandLine -like "*win_dsc*"} | Select-Object ProcessId, Name

# 终止目标进程
Stop-Process -Id <ProcessId> -Force

注意事项

  • 操作前务必备份C:\Windows\System32\Configuration目录下的所有文件,防止配置丢失。
  • 生产环境建议在维护窗口执行操作,避免影响业务运行。
  • 后续需排查DSC挂起的根本原因:比如自定义资源死锁、依赖服务未响应、权限不足等,避免问题重复出现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 11:37:23