Using –confirm and –whatif
We've already covered what the–confirm
and –whatif
risk mitigation parameters do. We've also seen how it's not difficult to include support for these parameters in your functions. It is now time to think about how to use them in a troubleshooting session. We will focus on –whatif
, but the discussion applies to –confirm
in exactly the same way. Obviously, if you are trying to troubleshoot a single function that includes support for –whatif
, you can add –whatif
to be sure that any system changes that the function would have made are skipped, while finding out what those would have been. This ability is incredibly beneficial to testing because we don't need to worry about the negative effects of running the code.
The way that the risk mitigation parameters (as well as the output preference parameters) work is something like the following. If you specify –whatif
in a function call, as the function enters scope, the $whatifpreference
variable is set to $true
. The $PSCmdlet...