在我们开发定制的DSC的资源时候,能Debug DSC的资源非常的重要。Debug DSC的资源的功能直到DSC 5.x 版本以后才支持。言归正传,开门见山,下面笔者描述一下如何进行PowerShell DSC资源的Debug。
@第1步: 开启Debug模式
执行这个命令,Enable-DscDebug -BreakAll 开启LCM的debug模式。
执行完后,调用Get-DscLocalConfigurationManager命令,确认:发现Debug的值已经改成了ForceModuleImport,ResourceScriptBreakAll
@第2步: 执行DSC脚本
以下面的脚本为例子,执行下面的脚本 configuration testzip{Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
Archive ArchiveExample {
Ensure = "Present" # You can also set Ensure to "Absent"
Path = "d:\DSC\22222.zip"
Destination = "d:\DSC\dd"
}
}
testzip
Start-DscConfiguration -path d:\DSC\testZip -wait -Verbose -Force
将会显示最下面的三行:
@第3步: 执行debug-runspace进入DSC 资源的代码
把上图中的这三条命令到另外一个ISE中,并执行就会进入debug模式。在控制台输入,可以参看单步的命令
参考文献:
https://msdn.microsoft.com/en-us/powershell/dsc/debugresource