TOPIC Preference Variables SHORT DESCRIPTION Variables that customize the behavior of Windows PowerShell LONG DESCRIPTION Windows PowerShell includes a set of variables that enable you to customize its behavior. These "preference variables" work like the options in GUI-based systems. The preference variables affect the Windows PowerShell operating environment and all commands run in the environment. In many cases, the cmdlets have parameters that you can use to override the preference behavior for a specific command. The following table lists the preference variables and their default values. Variable Default Value -------- ------------- $ConfirmPreference High $DebugPreference SilentlyContinue $ErrorActionPreference Continue $ErrorView NormalView $FormatEnumerationLimit 4 $LogCommandHealthEvent False (not logged) $LogCommandLifecycleEvent False (not logged) $LogEngineHealthEvent True (logged) $LogEngineLifecycleEvent True (logged) $LogProviderLifecycleEvent True (logged) $LogProviderHealthEvent True (logged) $MaximumAliasCount 4096 $MaximumDriveCount 4096 $MaximumErrorCount 256 $MaximumFunctionCount 4096 $MaximumHistoryCount 64 $MaximumVariableCount 4096 $OFS (Space character (" ")) $OutputEncoding ASCIIEncoding object $ProgressPreference Continue $PSEmailServer (None) $PSSessionApplicationName WSMAN $PSSessionConfigurationName http://schemas.microsoft.com/powershell/microsoft.powershell $PSSessionOption (See below) $VerbosePreference SilentlyContinue $WarningPreference Continue $WhatIfPreference 0 Windows Powershell also includes the following environment variables that store user preferences. For more information about the environment variables, see about_environment_variables. Variable -------- PSModulePath WORKING WITH PREFERENCE VARIABLES This document describes each of the preference variables. To display the current value of a specific preference variable, type the name of the variable. In response, Windows PowerShell provides the value. For example, the following command displays the value of the $ConfirmPreference variable. PS> $ConfirmPreference High To change the value of a variable, use an assignment statement. For example, the following statement assigns the value "Medium" to the $ConfirmPreference variable. PS> $ConfirmPreference = "Medium" Like all variables, the values that you set are specific to the current Windows PowerShell window. To make them effective in all Windows PowerShell windows, add them to your Windows PowerShell profile. For more information, see about_profiles. WORKING REMOTELY When you run commands on a remote computer, the remote commands are subject only to the preferences set in the Windows PowerShell client on the remote computer. For example, when you run a remote command, the value of the $DebugPreference variable on remote computer determines how Windows PowerShell responds to debugging messages. For more information about remote commands, see about_remote. $ConfirmPreference ------------------ Determines which cmdlet actions automatically request confirmation from the user before they are performed. When the $ConfirmPreference value (High, Medium, Low, None) is greater than or equal to the risk of the cmdlet action (High, Medium, Low, None), Windows PowerShell automatically requests confirmation from the user before performing the action. You can use the Confirm parameter of a cmdlet to override the preference for a specific command. Valid values: None: No cmdlet actions are automatically confirmed. Users must use the Confirm parameter to request confirmation of specific commands. Low: Cmdlet actions with a low, medium, or high risk are automatically confirmed. To suppress confirmation of a specific command, use -Confirm:$false. Medium: Cmdlet actions with a medium or high risk are automatically confirmed. To enable confirmation of a specific command, use -confirm. To suppress confirmation of a specific command, use -confirm:$false. High: Cmdlet actions with a high risk are automatically (default) confirmed. To enable confirmation of a specific command, use -confirm. To suppress confirmation for a specific command, use -confirm:$false. DETAILED EXPLANATION When a cmdlet action significantly affects the system, such as by deleting data or by using a significant amount of system resources, Windows PowerShell can automatically prompt you for confirmation before performing the action. For example, PS> remove-item pref2.txt Confirm Are you sure you want to perform this action? Performing operation "Remove File" on Target "C:\pref2.txt". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): The estimate of the risk is part of the cmdlet known as its "ConfirmImpact". You cannot change it. Cmdlet that might pose a risk to the system have a Confirm parameter that you can use to request or suppress confirmation for a specific command. Because most cmdlets use the default risk value of Medium, and the default value of $ConfirmPreference is High, automatic confirmation rarely occurs. However, you can activate automatic confirmation by changing the value of $ConfirmPreference to Medium or Low. EXAMPLES This example shows the effect of the default value of $ConfirmPreference. The High value only confirms high-risk cmdlet actions. Since most actions are of medium risk, they are not automatically confirmed, although you can use the Confirm parameter of the cmdlet to request confirmation of a specific command. PS> $confirmpreference #Get the current value of the High variable PS> remove-item temp1.txt #Delete a file PS> #Deleted without confirmation PS> remove-item temp2.txt -confirm #Use the Confirm parameter Confirm Are you sure you want to perform this action? Performing operation "Remove File" on Target "C:\temp2.txt". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): This example shows the effect of changing the value of $ConfirmPrefernce to Medium. Because most cmdlet actions are medium-risk, they are automatically confirmed, and you have to use the Confirm parameter with a value of $false to suppress the confirmation prompt for a specific command. PS> $confirmpreference = "Medium" #Change the value of $ConfirmPreference PS> remove-item temp2.txt #Deleting a file triggers confirmation Confirm Are you sure you want to perform this action? Performing operation "Remove File" on Target "C:\temp2.txt". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): PS> remove-item temp3.txt -confirm:$false #Use Confirm parameter to suppress confirmation PS> $DebugPreference ------------------ Determines how Windows PowerShell responds to debugging messages generated by a script, cmdlet or provider, or by a Write-Debug command at the command line. Some cmdlets display debugging messages, which are typically very technical messages designed for programmers and technical support professionals. By default, debugging messages are not displayed, but you can display debugging messages by changing the value of $DebugPreference. You can also use the Debug common parameter of a cmdlet to display or hide the debugging messages for a specific command. For more information, type: "get-help about_commonparameters". Valid values: Stop: Displays the debug message and stops executing. Writes an error to the console. Inquire: Displays the debug message and asks you whether you want to continue. ...
magdula294