How Confirmation Works in PowerShell

All PowerShell cmdlets that modify the system in some fashion are supposed to support the -confirm parameter. When run with -confirm (or -whatif, which is supported if -confirm is), the cmdlet will ask you to verify each action it takes. For example:
Get-Process | Stop-Process -confirm
Any cmdlet that declares support for -confirm also declares its confirm impact. That impact is simply "Low," "Medium," or "High," based on the cmdlet author's perception of how potentially deadly the cmdlet is. The shell also has a built-in $ConfirmPreference variable, which by default is set to "High." Here's how it works: If you run a cmdlet whose impact is equal to or higher than $ConfirmPreference, then confirmation happens automatically, whether you specify the -confirm parameter or not. 

Suppose you run across a cmdlet that automatically confirms (Set-ExecutionPolicy and Enable-PSRemoting are two examples), but you want to suppress the confirmation? Just do this:
Enable-PSRemoting -confirm:$false
That shuts off the automatic confirmation, allowing the cmdlet to run without asking you if you're sure. Be careful!

Please or Register to post comments.

What's PowerShell with a Purpose Blog?

Don Jones demystifies Windows PowerShell.

Blog Archive

Sponsored Introduction Continue on to (or wait seconds) ×