How Confirmation Works in PowerShell

PowerShell doesn't often ask "Are You Sure?" Here's when, and how to control it.

Don Jones

June 27, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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!

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like