Exchange Powershell and Whatif

So I have been creating a few scripts to automate the configuration of exchange, and wanted to use the -WhatIf switch so you can see what would or would not change.

-WhatIf []
The WhatIf parameter instructs the command to simulate the actions that it would take on the object. By using the WhatIf parameter, you can vi ew what changes would occur without having to apply any of those changes. You don’t have to specify a value with the WhatIf parameter.

Now typically you would just use the -whatif switch after the command, but I just wanted one command and have the ability to turn on or off the switch, but keep the same line of code.

So I had a brain storm on the way in to work this morning and after a little try found out something (which If I have read the help listed above would have come quicker!)

So here we go, you can specify a $true or $false after the -WhatIf switch.  So what  you say, well you can pass that via a variable and that make things a whole lot more fun. so … the key here is the colon between -WhatIf and $True or $False


$xWhatIf = $true

Get-TransportServer LONINMEXD02  | Set-TransportServer -OutboundConnectionFailureRetryInterval 00:10:00 -WhatIf:$xWhatIf

What if: Setting transport server “”.

** Value is not set **

$xWhatIf = $false

Get-TransportServer LONINMEXD02  | Set-TransportServer -OutboundConnectionFailureRetryInterval 00:10:00 -WhatIf:$xWhatIf

** Value IS set **


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: