Common Parameters

PowerShell includes several common parameters that all cmdlets support.
Their short aliases are listed in (parentheses).

   -Confirm       Prompt the user for permission before performing any action that
                  modifies the system.[boolean] (cf)
                  -Confirm:$false or -Confirm:$true

   -Debug         Provide programming-level information about the operation [boolean] (db)
                  $true (-Debug:$true). Has the same effect as -Debug.

   -ErrorAction   Control command behavior when an error occurs [enum] (ea)
                  Valid values: Continue [default], Stop, Suspend, SilentlyContinue, Ignore, Inquire. [Enum]
                  e.g. -EA SilentlyContinue

   -ErrorVariable Name of variable (in addition to $error) in which 
                  to place objects to which an error has occurred [string] (ev)

                  Override the value of the $InformationPreference preference variable. (ia)
                  Valid values: SilentlyContinue, Stop, Continue, Inquire, Ignore, Suspend 

   -InformationVariable [+]variable_name    
                  Store into a variable a string that you specify with Write-Information. 
                  PowerShell 5.0+

   -OutBuffer     The number of objects to buffer before calling the next 
                  cmdlet in the pipeline.[Int32] (ob)

   -OutVariable   Name of variable in which to place output objects [string](ov)
                  (equivalent to piping the command Set-Variable -passthru true)

   -PipelineVariable (pv)
                  Stores the value of the current pipeline element as a variable, for
                  any named command as it flows through the pipeline.
                  Valid values are strings, the same as for any variable names.

   -Verbose       Provide detailed information about the operation [boolean] (vb)
                    $true (-Verbose:$true) has the same effect as -Verbose.
                    $false (-Verbose:$false)

   -WarningAction Determines how the cmdlet responds to a warning from the command.(wa)
                  "Continue" is the default value. This parameter works only when the
                  command generates a warning message. For example, this parameter
                  works when a command contains the Write-Warning cmdlet.

                  Stores warnings about the command in the specified variable. (wv)
                  All generated warnings are saved in the variable even if the
                  warnings are not displayed to the user.
                  To append the warnings to the variable content, instead of replacing
                  any warnings that might already be stored there, type a plus sign (+)
                  before the variable name.  -WarningVariable +myvar

   -WhatIf        Explain what will happen if the command is executed, without actually
                  executing the command.[boolean] (wi)
                  -whatif:$false or -whatif:$true

                  values are shown depending on the value of the -InformationAction
                  common parameter; if you do not add the -InformationAction common parameter,
                  Write-Information strings are shown depending on the value of the $InformationPreference

An Error Variable can be useful for logging errors as part of a pipeline process i.e. when only a few out of many items may fail:

PS C:> some-pscmdlet | foreach {
  another-pscmdlet -options blah -errorvariable ErrFlag
  if ($ErrFlag) { Echo "$ failed" }

The -confirm parameter allows dropping into the runtime command line while running a PowerShell scriptCmdlet:
The confirmation prompt is [Y] Yes [A] All [N] No [L] No to all [S] Suspend
choosing S will drop you at the command prompt where you can echo variables, make changes etc before typing EXIT to resume running the scriptCmdlet.

Default values

Other than where stated above, none of the common parameters have a defined default value, so they will evaluate as FALSE.

You can set a default value, for the duration of a script or a session using $PSDefaultParameterValues, for example you could set the value of WhatIf to TRUE at the start of a script and this will affect every cmdlet in the script

$PSDefaultParameterValues['*:WhatIf'] = $true

Some common parameters may have no effect in some cmdlets, this does not raise an error.

Aliases: -ErrorAction and -ErrorVariable, have defined parameter aliases so you can just type -EA and -EV


PS C:\> Del $somefile -ErrorVariable somevariable

Notice that the error variable is not prefixed with a $ here, using $somevariable will not work.

If the ErrorVariable name is prefixed with a + then PowerShell will ADD the errors to that variable:

PS C:\> Del $somefile -ErrorVariable +somevariable
PS C:\> $somevariable.count

“Friendship is born at that moment when one person says to another, What! You, too? I thought I was the only one” ~ C. S. Lewis

Related PowerShell Commands:

Parameters - Command Line Parameters param() and $args[]
get-help - Open the help file, list parameters for a cmdlet.

Copyright © 1999-2018
Some rights reserved