Search notes:

PowerShell: the preference variable $confirmPreference

Each PowerShell command (cmdLets, aliases etc.) is assigned a System.Management.Automation.ConfirmImpact enum-value. The possible values of ConfirmImpact are:
For a given command, such as for example stop-process, the respective value can be determined like so:
PS C:\> $stopProcMeta = new-object System.Management.Automation.CommandMetadata(get-command stop-process)
PS C:\> $stopProcMeta.ConfirmImpact
Medium
Now, if the value of the preference variable $confirmPreference is lower than that of a command, the command requires the user to confirm the required action.
I try to demonstrate that in the following example. By default, the value of $confirmPreference is High:
PS C:\> $confirmPreference
High
Because the value of ConfirmImpact of stop-process is Medium only, I can use stop-process without being asked for confirmation:
PS C:\> start-process notepad
PS C:\> stop-process -name notepad
However, If I set the value of $confirmPreference to Medium, I will be asked to confirm the killing of a process:
PS C:\> start-process notepad
PS C:\> $confirmPreference = 'medium'
PS C:\> stop-process -name notepad

Confirm
Are you sure you want to perform this action?
Performing the operation "Stop-Process" on target "notepad (37468)".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

Links

PowerShell Team: ConfirmPreference

Index