2

#PSTip List all cmdlets that accept a specific object type as input

Note: This tip requires PowerShell 3.0 or above.

At times, we find the need to list all cmdlets that accept a specific type of object as input. In PowerShell 3.0, the –ParameterType parameter of the Get-Command cmdlet can be used to retrieve this list.

PS C:\> Get-Help Get-Command -Parameter ParameterType
-ParameterType
Gets commands in the session that have parameters of the specified type. Enter the full name or partial name of a parameter type. Wildcards are supported.

The ParameterName and ParameterType parameters search only commands in the current session.
This parameter is introduced in Windows PowerShell 3.0.

As mentioned in the help text, the value of this parameter can be the full PS type name:

Get-Command -ParameterType System.Diagnostics.Process

Or we can use wildcards as well – in case we don’t know the full type name:

Get-Command -ParameterType *uri*

Or we can pass the PSTypeNames property of an object and derive the cmdlets that support the object type as input:

PS C:\> Get-Command -ParameterType (((Get-Process)[0]).PSTypeNames)
CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Debug-Process                                      Microsoft.PowerShell.Management
Cmdlet          Get-Process                                        Microsoft.PowerShell.Management
Cmdlet          Stop-Process                                       Microsoft.PowerShell.Management
Cmdlet          Wait-Process                                       Microsoft.PowerShell.Management
Filed in: Columns, Tips and Tricks Tags: , , ,

2 Responses to "#PSTip List all cmdlets that accept a specific object type as input"

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: