4

Is it possible to run a DSC configuration and get the WhatIf output from Set-TargetResource? I've written a custom resource, and the Set function has all the necessary code for WhatIf/ShouldProcess to work (and indeed, if you call Set-TargetResource manually with -WhatIf, it works as expected).

When calling Start-DSCConfiguration with -WhatIf, all I get is this:

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      ]

When what I really want is for it to call the Test function for real, and then call Set with -WhatIf so that I get this output (generated by my calls to ShouldProcess() within Set-TargetResource:

What if: Performing the operation "Create Directory" on target "/ifs/a".
What if: Performing the operation "Create Share" on target "/ifs/a".

Is that possible?

Jack
  • 115
  • 7

1 Answers1

0

No, you cannot do that. Manually is the only way for it to work.

As you experienced, the -whatif will tell you what resources would get called but does not call them. Your function needs to get called for the whatif inside it to process.

kevmar
  • 808
  • 6
  • 6