PowerShell for Windows Admins

Mar 5 2018   7:00AM GMT

Cmdlet parameters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I discovered another way to investigate cmdlet parameters.

If you dig into the output of Get-Command you’ll see it has a parameters property

PS> Get-Command Clear-RecycleBin | select parameters

{[DriveLetter, System.Management.Automation.ParameterMetadata], [Force, System.Management.Automation.ParameterMetada...

If you expand the parameters property:

PS> Get-Command Clear-RecycleBin | select -ExpandProperty parameters

Key Value
--- -----
DriveLetter System.Management.Automation.ParameterMetadata
Force System.Management.Automation.ParameterMetadata
Verbose System.Management.Automation.ParameterMetadata
Debug System.Management.Automation.ParameterMetadata
ErrorAction System.Management.Automation.ParameterMetadata
WarningAction System.Management.Automation.ParameterMetadata
InformationAction System.Management.Automation.ParameterMetadata
ErrorVariable System.Management.Automation.ParameterMetadata
WarningVariable System.Management.Automation.ParameterMetadata
InformationVariable System.Management.Automation.ParameterMetadata
OutVariable System.Management.Automation.ParameterMetadata
OutBuffer System.Management.Automation.ParameterMetadata
PipelineVariable System.Management.Automation.ParameterMetadata
WhatIf System.Management.Automation.ParameterMetadata
Confirm System.Management.Automation.ParameterMetadata

The really nice thing is that you get the common parameters listed as well.

If you want to dig into the individual parameters

PS> $params = Get-Command Clear-RecycleBin | select -ExpandProperty parameters

PS> $params.DriveLetter

Name : DriveLetter
ParameterType : System.String[]
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic : False
Aliases : {}
Attributes : {__AllParameterSets, System.Management.Automation.ValidateNotNullOrEmptyAttribute}
SwitchParameter : False


PS> $params.Verbose

Name : Verbose
ParameterType : System.Management.Automation.SwitchParameter
ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic : False
Aliases : {vb}
Attributes : {System.Management.Automation.AliasAttribute, __AllParameterSets}
SwitchParameter : True

You can see the parameter sets and aliases which is useful. The parameter type indicates the input data.

This is very useful where you haven’t installed the help files on a system

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: