How-to: PowerShell Preference Variables

PowerShell preferences, items shown thus are available in PS 5.0, but undocumented and possibly unavailable in PS 7.0:

    Variable                       Default Value     Possible values
    --------                       -------------     --------------------------------
    $ConfirmPreference             High              High, Medium, Low, or None.

    $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

    $ErrorView                     NormalView in PS 5,
                                   ConciseView in PS 7  NormalView, CategoryView, or ConciseView.

    $FormatEnumerationLimit        4                 Any Int32 number.

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

    $LogCommandHealthEvent 	       $False            $True (Logged) or $False (not logged)
    $LogCommandLifecycleEvent 	   $False            $True (Logged) or $False (not logged)
    $LogEngineHealthEvent 	       $True             $True (Logged) or $False (not logged)
    $LogEngineLifecycleEvent       $True             $True (Logged) or $False (not logged)
    $LogProviderLifecycleEvent     $True             $True (Logged) or $False (not logged)
    $LogProviderHealthEvent        $True             $True (Logged) or $False (not 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 character (" ")  (converting an array to string.)
    $OutputEncoding                ASCIIEncoding
                                   Valid values: Objects derived from an Encoding class, such as:
                                       ASCIIEncoding, SBCSCodePageEncoding, UTF7Encoding,
                                       UTF8Encoding, UTF32Encoding, and UnicodeEncoding.

                                   The $OutputEncoding preference only applies to how PowerShell communicates with external
                                   programs (sending strings) it has nothing to do with the encoding that the PS output
                                   redirection operators and PowerShell cmdlets use to save to files. [more]

    $ProgressPreference            Continue       (stop | Inquire | continue | SilentlyContinue)

    $PSDefaultParameterValues      @{} (empty hash table)     Introduced in PS 3.0
    $PSEmailServer                 $Null (none)
    $PSModuleAutoLoadingPreference 	All
    $PSModuleAutoloading           Import installed modules automatically.
    $PSSessionApplicationName      'wsman'
    $PSSessionConfigurationName    'http://schemas.microsoft.com/powershell/Microsoft.PowerShell'
    $PSSessionOption               See New-PSSessionOption
    $Transcript                    $Null (none)

    $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

    $WhatIfPreference 	           $False

The 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.

The $PSDefaultParameterValues preference variable lets you specify custom default values for just one specific cmdlet or advanced function, see Help about_Parameters_Default_Values for more.

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-2024 SS64.com
Some rights reserved