What if you just deleted 5000 accounts from your active directory domain by accident, what if there had been an easy way to make sure you were doing the right thing before the deletion. Would you have wanted to use it? I know I would. Just imagine you were planning on deleting all accounts which had been disabled for six months but you forgot some important switch and most of your accounts were gone because of that stupid switch. Ok, so this might be a bit far fetched but these things can happen and if you are not 100 percent sure of what you are doing, it’s great to be able to see what the results of your actions will be before you take them.
Let’s say we’ve been taking random notes and just want to kill all notepad processes without having to choose if we want to save every single file. Working with the Get-Process, Where-Object and Stop-Process cmdlets we decide to kill all the processes which has “note” in them.
This would have wiped out every instance of notepad.exe along with my Onenote and notepad++ processes which was not what I wanted.
Yes, I guess you’re right that was quite a lame example. However I think it does illustrate how you can use the -whatif parameter. It can be very useful if you are working with important data and don’t want to make mistakes. Also it’s useful if your just playing around with PowerShell and learning what all the fuss is about.