Common Parameters

PowerShell includes several common parameters that all cmdlets support.

   -Verbose        Generate detailed trace info about the operation.(Boolean)

   -Debug          Generate programmer-level detail about the operation.(Boolean)
    
   -ErrorAction    Determine how the cmdlet responds when an error occurs.
                   Values are: Continue [default], Stop, SilentlyContinue, Inquire. (Enum)

   -ErrorVariable  Specify a variable to store errors from the command during processing.
                   This variable is populated in addition to $error. (String)

   -OutVariable    Specify a variable to store output from the command during processing.(String)

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

System State Parameters:

   -WhatIf         Explain what will happen if the command is executed, without actually
                   executing the command.(Boolean)

   -Confirm        Prompt the user for permission before performing any action that
                   modifies the system.(Boolean)

Ubiquitous Parameters:

    -Confirm       Prompt the user for permission before performing any action that
                   modifies the system.(Boolean)

    -Debug         Provide programming-level information about the operation (boolean)

    -ErrorAction   Control command behavior when error occurs (enum)

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

    -OutputBuffer  Control the number of objects to be buffered between this 
                   command and the next (useful for tweaking performance) (int32)
                          
    -OutVariable   Name of variable in which to place output objects
                   (equivalent to piping the command Set-Variable -passthru true) (string)

    -Verbose       Provide detailed information about the operation (boolean)

    -WhatIf        Explain what will happen if the command is executed, without actually
                   executing the command.(Boolean)

$ErrorVariable 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 "$_.name failed" }
}

The -confirm parameter allows dropping into the runtime command line while running a PowerShell v2 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.

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

Examples

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

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

“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:

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


© Copyright SS64.com 1999-2014
Some rights reserved