Childproofing PowerShell

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!


Posted Jan 11 2010, 08:00 AM by ps1

Comments

Georgiy wrote re: Childproofing PowerShell
on 01-12-2010 11:06 AM

can you give more samples? i am not realy undestood this staff.

Episode 98 – Steven Murawsk on PowerShellCommunity.org and Debugging « PowerScripting Podcast wrote Episode 98 – Steven Murawsk on PowerShellCommunity.org and Debugging « PowerScripting Podcast
on 01-18-2010 12:07 AM

Pingback from  Episode 98 – Steven Murawsk on PowerShellCommunity.org and Debugging «  PowerScripting Podcast

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.