Childproofing PowerShell

by Jan 11, 2010

If you are new to PowerShell, you may be worried about causing unwanted damage or change. One way of childproofing PowerShell is by changing the whatif-default like so:

$whatifpreference = $true

From now on, any cmdlet supporting the -whatif parameter will use it without you having to specify it. So any cmdlet that would change things on your system is effectively disabled. This affects anything that changes things, even creating a new folder is not allowed anymore:

Md c:\test

To override the default, you need to explicitly add this option: -whatif:$false

Md c:\test -whatif:$false

Twitter This Tip! ReTweet this Tip!