7

Is there a way to change the default confirmation option for a High Impact PowerShell script?

When I implement a Cmdlet and run it asking for Confirmation like

MyPS

Confirm
Are you sure you want to perform this action?    
Performing operation "XYZ" on Target "123".
[Y] Yes [A] Yes to All [N] No [L] No to all [S] Suspend [?] Help (default is "Y"):

How can I change the default value? I want to change the default from "Y" to "N".

Troyen
  • 1,398
  • 2
  • 23
  • 37
user3006883
  • 71
  • 1
  • 2

1 Answers1

2

It's a little unclear what you're trying to ask. Do you want to know how to set a global default (for a given PowerShell session) to suppress confirmation prompts for cmdlets that prompt for confirmation by default, so you don't have to keep specifying -Confirm:$false every time you run them? Set the default variable:

$ConfirmPreference = $false

Or are you asking how to change the confirm impact for a specific cmdlet? Declare [CmdletBinding(ConfirmImpact = 'high')] at the beginning of your script. Note that if you declare CmdletBinding, a param() block is required, even if it's empty.

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
  • I want the confirmation however something like [Y] Yes [A] Yes to All [N] No [L] No to all [S] Suspend [?] Help (default is "N"): – user3006883 Nov 19 '13 at 01:31
  • [CmdletBinding(ConfirmImpact = 'high')] just make to ask for the confirmation, However not let you change the default options in the confirmation. The default option is Yes ((default is "Y")), need to change it to No (default is "N") – user3006883 Nov 19 '13 at 01:39
  • Ah...that's very different. Good question...I'm not aware of a way to change that, but I can't say I've ever looked into it. Usually if I don't want to use the default behavior I add `if ($PSBoundParameters.Confirm) {$ConfirmPreference = 'SilentlyContinue'}` at the beginning, then implement my own confirmation prompts. But maybe there's a built-in way if you want to make a minor change like that. – Adi Inbar Nov 19 '13 at 01:41
  • [tag:powershell] still asks for confirmation for`set-winuserlanguagelist` even when `$confirmpreference` is `'none'` (out of the four enumerators). –  Sep 06 '17 at 09:44