Solaflex
Solaflex

Reputation: 1432

-Confirm:$false set as global setting

I have a few powershell scripts which trigger from a C# codepart.

They run non-interactive and there is no way to confirm any command.

In Powershell, we can set the ErrorActionPreference global with $ErrorActionPreference = "Stop"

Is there a same way to set on each command the confirm parameter to $false if it exists ?

Upvotes: 6

Views: 2210

Answers (3)

user2366586
user2366586

Reputation:

Take a look here

You can set the global behavior with

$ConfirmPreference = "None" / "Low" / "High"

Upvotes: 1

Shay Levy
Shay Levy

Reputation: 126702

You can check if the command supports Confirm and set it using splatting:

$param = @{}
if((Get-Command Enable-PSRemoting).Parameters.Confirm) {$param.Confirm=$false}

Enable-PSRemoting @param

In PowerShell 3.0 you can use the $PSDefaultParameterValues variable:

$PSDefaultParameterValues["*:Confirm"]=$false

Upvotes: 0

CB.
CB.

Reputation: 60910

You can try with:

$ConfirmPreference = "None"

Read here

Upvotes: 4

Related Questions