Skip to content

Latest commit

 

History

History

Local-ActionPreference

Local action preference variables

Action preference variables and their default values:

  • $ErrorActionPreference Continue
  • $WarningPreference Continue
  • $DebugPreference SilentlyContinue
  • $VerbosePreference SilentlyContinue
  • $ProgressPreference Continue

Valid values:

PS> [enum]::GetNames([System.Management.Automation.ActionPreference])
SilentlyContinue
Stop
Continue
Inquire
Ignore
Suspend

Ignore was added in PowerShell 3.0. Suspend was added in PowerShell 4.0.

The problem

Not global action preference variables are not strongly typed. As a result, anything can be assigned to them, not necessarily valid values. For example, typos will not be reported as errors, unlike with global variables.

As a result, cmdlets or scripts which in some rare cases use these variables directly should not expect that their type is ActionPreference or they are assigned to string or integer values representing enum values correctly.

Assigning valid string or integer values to local preference variables changes default action preferences accordingly. Invalid values are treated as Continue or SilentlyContinue depending on a variable, see tests.

Scripts