What if the deploy to production will screw up the environment?
What if I want to investigate a script by running it?
What if I don’t trust what a script is doing?
What if I want to execute the code in a script to see it is working, but I do not want it to fiddle with my environment?
Well, Powershell has this feature. It’s called the WhatIf flag.
It’s mostly a convention how you write your script, no magic, but in some cases you get some help from the script parser.
Basically it’s a command line flag, a tristate option. The type is [switch], a nullable bool. When it’s unset or $false, your script should perform as usual. When it’s $true, your script should not perform any actions which cause side effects. Compare to the GET action in HTTP, and to functions in functional programming languages.
In most cases your script does not need to add this flag to every internal function call, it’s automatically propagated to functions as a global variable. The two cases where you need to explicit add this flag is when performing calls over module boundaries (to .psm1 libraries) and when performing remote calls to other computers.
Nearly all native Powershell commands which cause side effects accept this option, and sometimes modules also implements it.
In our deploy script which we recently developed, we exposed this flag as an environment variable which could be set in the deploy server’s web GUI.

Postat i:Uncategorized