是否可以运行DSC配置并从Set-TargetResource获取WhatIf输出?我编写了一个自定义资源,并且Set函数具有WhatIf / ShouldProcess工作所需的所有代码(实际上,如果使用-WhatIf手动调用Set-TargetResource,它会按预期工作)。
当用-WhatIf调用Start-DSCConfiguration时,我得到的是:
What if: [SERVERNAME]: LCM: [ Start Set ]
What if: [SERVERNAME]: LCM: [ Start Resource ] [[Isi_Share]test]
What if: [SERVERNAME]: LCM: [ Start Test ] [[Isi_Share]test]
What if: [SERVERNAME]: LCM: [ End Test ] [[Isi_Share]test] in 0.0310 seconds.
What if: [SERVERNAME]: LCM: [ Skip Set ] [[Isi_Share]test]
What if: [SERVERNAME]: LCM: [ End Resource ] [[Isi_Share]test]
What if: [SERVERNAME]: LCM: [ Start Resource ] [[Isi_Share]test2]
What if: [SERVERNAME]: LCM: [ Start Test ] [[Isi_Share]test2]
What if: [SERVERNAME]: LCM: [ End Test ] [[Isi_Share]test2] in 0.0470 seconds.
What if: [SERVERNAME]: LCM: [ Start Set ] [[Isi_Share]test2]
What if: [SERVERNAME]: LCM: [ End Set ] [[Isi_Share]test2] in 0.0150 seconds.
What if: [SERVERNAME]: LCM: [ End Resource ] [[Isi_Share]test2]
What if: [SERVERNAME]: LCM: [ End Set ]
当我真正想要的是它将Test函数调用为real,然后使用-WhatIf调用Set以便我获得此输出(由我在Set-TargetResource中调用ShouldProcess()生成:
What if: Performing the operation "Create Directory" on target "/ifs/a".
What if: Performing the operation "Create Share" on target "/ifs/a".
这可能吗?
答案 0 :(得分:0)
不,你不能这样做。手动是它工作的唯一途径。
正如您所经历的那样,-whatif将告诉您将调用哪些资源但不会调用它们。你的函数需要调用它内部的whatif进行处理。