如何解决“无法调用SendConfigurationApply方法”。何时执行Start-DscConfiguration?

时间:2014-09-16 19:39:04

标签: powershell powershell-v4.0 dsc

另一种不太具体的问题:在目标机器上“重置”DSC过程的正确方法是什么?

我已经创建了一个我正在迭代的DSC配置,我正在添加新的Package配置,我已经错了。我确定通过忘记在Package块中向MSI安装程序提供/ quiet参数,我可以使Start-DscConfiguration cmdlet“挂起”。

在此'hang'开始时,我在本地计算机上停止DSC配置操作并尝试纠正配置问题(通过在我的示例中添加/ quiet参数)然后重新启动DSC操作。现在我在操作期间看到了以下远程机器:

Cannot invoke the SendConfigurationApply method. The PerformRequiredConfigurationChecks method is in progress and must return before SendConfigurationApply can be invoked.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : REMOTEMACHINE20

不幸的是,访问正在配置的远程PC我看到类似的错误消息,并且重新启动PC似乎没有纠正错误。

我在网上看到过一些关于这个问题的帖子,到目前为止我发现了三个帖子:

  1. “等一会儿,它会自行解决”,这对我没用(也许我很不耐烦......)。不是一个成熟的长期解决方案。
  2. “删除所有本地.mof文件,然后重试”,这对我来说也没用。
  3. Stop all processes with 'wmi' in the name and restart the winrm service on the target machine(s).这让我畅通无阻,但我希望有更好的方法可以解决这个问题。 (如果我在接下来的几天内没有听到更好的方法,我会自己用这个程序回答这个问题,以获得所需的结果。)

2 个答案:

答案 0 :(得分:16)

我发现以下效果非常适合重置DSC。请注意,这将删除本地配置,因此您需要重新应用machinename.meta.mof文件。

#Remove all mof files (pending,current,backup,MetaConfig.mof,caches,etc)
rm C:\windows\system32\Configuration\*.mof*
#Kill the LCM/DSC processes
gps wmi* | ? {$_.modules.ModuleName -like "*DSC*"} | stop-process -force

此时,您已准备好使用Set-DscLocalConfigurationManager配置的干净系统,并使用Update-DscConfiguration -Wait -Verbose -CimSession machinename进行更新

到目前为止,唯一没有解决的问题是损坏的$ env:psmodulepath或者缺少Consistency / Reboot检查的计划任务。 更新:根据this item on connect,WMF 5.0二月预览中删除了一致性/重新启动的计划任务。

答案 1 :(得分:4)

您也可以尝试使用-Force选项

执行start-dscconfiguration命令
Start-DscConfiguration -Force ...