Home PowerShell Internals Help Listing Common Parameters
 

Listing Common Parameters

If you ever wondered how to find out a list of common parameters (other than hard-coding it), here is a way. It not only returns the list of common parameters but also their data type and the hidden alias names that you can use as a shortcut:

  

[System.Management.Automation.Internal.CommonParameters].GetProperties() |
ForEach-Object {
  $rv = $_ | Select-Object -Property Name, PropertyType, Alias
  $rv.Alias = $_.CustomAttributes.ConstructorArguments.Value.Value -join ','
  $rv
}

  Getting a list of all common parameters

The result will look similar to this:

Name                       PropertyType               Alias                   
—-                       ————               —–                   
Verbose                    System.Management.Autom… vb                      
Debug                      System.Management.Autom… db                      
ErrorAction                System.Management.Autom… ea                      
WarningAction              System.Management.Autom… wa                      
ErrorVariable              System.String              ev                      
WarningVariable            System.String              wv                      
OutVariable                System.String              ov                      
OutBuffer                  System.Int32               ob                      
PipelineVariable           System.String              pv 

Compatibility with PowerShell 2.0

Note that this code will run only in PowerShell 3.0 due to the automatic unrolling used. In PowerShell 2.0, you would have to write a lot more code:

  

[System.Management.Automation.Internal.CommonParameters].GetProperties() |
ForEach-Object {
  $rv = $_ | Select-Object -Property Name, PropertyType, Alias
  $rv.Alias = ($_.CustomAttributes | Select-Object -ExpandProperty ConstructorArguments | Select-Object -ExpandProperty Value ).Value -join ','
  $rv
}

  The same result, but without using PSv3 "Automatic Unrolling"

When you pipe the results to Out-GridView, you get a nice overview, too:

Examining Common Parameters