In PowerShell, the $ConfimPreference variable is set to “High” by default. What does this setting control?
PS> $ConfirmPreference High
Any PowerShell command (binary cmdlet or function) can set its own “ConfirmImpact”: allowable values are: None, Low, Medium, and High. ConfirmImpact is an assessment how critical the effect of the cmdlet is.
By default, when $ConfirmImpact is set to “High”, PowerShell will automatically ask for confirmation whenever you run a cmdlet or function which has set its ConfirmImpact to High (so you will only see confirmation dialogs pop up when you run cmdlets that permanently delete things such as AD account that cannot be restored easily).
As a user, you can adjust this risk mitigation system. If you are working on an extra sensitive production system, you may want to lower $ConfirmPreference to Medium or even Low to get more confirmations when you run PowerShell commands or scripts. When set to “Low”, even creating a new folder will trigger an automatic confirmation:
PS> $ConfirmPreference = 'Low' PS> New-Item -Path c:\testfolder Confirm Are you sure you want to perform this action? Performing the operation "Create File" on target "Destination: C:\testfolder". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
Likewise, if you want to run a script unattended and if you must make sure it won’t be interrupted by automatic confirmation dialogs, set $ConfirmPreference to “None”, effectively turning off this risk mitigation system. This is much more efficient than manually overriding automatic confirmation by adding the -Confirm:$false parameter to every single command in your script that could possibly trigger a confirmation.
Any changes to $ConfirmPreference will revert to default when you close your current PowerShell session. They are not automatically persisted. If you want to permanently change these settings, create a profile script and add all permanent changes to this script. It will launch automatically when PowerShell launches.
The path to such a profile script can be found here:
PS> $profile.CurrentUserAllHosts C:\Users\USERNAME\OneDrive\Documents\WindowsPowerShell\profile.ps1