Reputation: 1432
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
Reputation:
Take a look here
You can set the global behavior with
$ConfirmPreference = "None" / "Low" / "High"
Upvotes: 1
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