Reputation: 71
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".
Upvotes: 7
Views: 4258
Reputation: 12323
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.
Upvotes: 2