How-to: PowerShell Preference Variables

PowerShell preferences:

    Variable                       Default Value     Possible values
    --------                       -------------     --------------------------------

    $DebugPreference               SilentlyContinue  (Stop | Inquire | Continue | SilentlyContinue)
    Used by: Write-Debug
             Error stream 5

    $ErrorActionPreference         Continue          (Stop | Inquire | Continue | SilentlyContinue | Break)
    Used by: Write-Error                             [Suspend and Ignore are for per-command use only.]
             Error stream 2

    $InformationPreference         SilentlyContinue  (Stop | Inquire | Continue | SilentlyContinue)
    Used by: Write-Information  
             Error stream 6

    $VerbosePreference             SilentlyContinue  (Stop | Inquire | Continue | SilentlyContinue)
    Used by: Write-Verbose
             Error stream 4

    $WarningPreference             Continue          (Stop | Inquire | Continue | SilentlyContinue)
    Used by: Write-Warning
             Error stream 3

    n.b. Error stream 1 is for Std Output (Write-Output) this has no corresponding preference variable.
         Write-Host writes to Error stream 6 (the same as Write-Information) but it has no preference variable
         so in effect Write-Host is always set to Continue and will always display unless stream 6 is redirected.

    $ErrorView                     NormalView        (NormalView | CategoryView)
    $FormatEnumerationLimit        4
    $ConfirmPreference             High              (none | low | medium | high)
    $LogCommandHealthEvent         False (not logged)
    $LogCommandLifecycleEvent      False (not logged)
    $LogEngineHealthEvent          True (logged)
    $LogEngineLifecycleEvent       True (logged)
    $LogProviderLifecycleEvent     True (logged)
    $LogProviderHealthEvent        True (logged)
    $MaximumAliasCount             4096     Max no. of aliases available to the session. Valid values: 1024-32768
    $MaximumDriveCount             4096     Max no. of drives available, excluding those provided by the OS.
    $MaximumErrorCount             256      Valid values: 256 - 32768
    $MaximumFunctionCount          4096     Max no. of functions available to the session.
    $MaximumHistoryCount           64       Max no. of entries saved in the command history. Valid values: 1-32768
    $MaximumVariableCount          4096     Max no. of variables available to the session.
    $OFS                           Space " "  Output Field Separator (converting an array to string.)

    $OutputEncoding                ASCIIEncoding
                                   Valid values: Objects derived from an Encoding class, such as:
                                       ASCIIEncoding, SBCSCodePageEncoding, UTF7Encoding,
                                       UTF8Encoding, UTF32Encoding, and UnicodeEncoding.

    $ProgressPreference            Continue       (stop | Inquire | continue | SilentlyContinue)
    $PSEmailServer                 (None)
    $PSModuleAutoloading           Import installed modules automatically.
    $PSSessionApplicationName      WSMAN
    $PSSessionConfigurationName    http://schemas.microsoft.com/powershell/microsoft.powershell 
    $PSSessionOption               See New-PSSessionOption
    $WhatIfPreference              0

Examples

Display the value of the $ConfirmPreference variable.

PS C:\> $ConfirmPreference
High

View the name and value of a preference variable:

PS C:\> get-variable DebugPreference
Name              Value
----              -----
DebugPreference   Silently Continue

Assign the value 'Medium' to the $ConfirmPreference variable.

PS C:\> $ConfirmPreference = 'Medium'

Setting $OFS (the Output Field Separator) to display an array with different separators:

PS C:\> &{ $a = 1,2,3; "$a"}
  1 2 3

PS C:\> &{ $OFS="-"; $a = 1,2,3; "$a"}
  1-2-3

"Democracy cannot be static. Whatever is static is dead" ~ Eleanor Roosevelt

Related PowerShell Cmdlets:

Common Parameters - Debug, -ErrorAction, -OutVariable, -Verbose etc
How-to: Redirection (streams 1 - 6)
Variables - Environment variables.
Automatic variables - Variables created and maintained by PowerShell $_, $Args, $Error, $Home etc.
Array Variables
help about_preference_variables


 
Copyright © 1999-2020 SS64.com
Some rights reserved