PowerShell with a Purpose Blog

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!
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.