Create a gist now

Instantly share code, notes, and snippets.

Gets command parameters that have the specified parameter type
<#
.SYNOPSIS
Gets parameters with the specified parameter type
.DESCRIPTION
The Get-ParameterType.ps1 gets parameters with the specified parameter type. It returns the command name, parameter name, and parameter type in a PSCustomObject.
This script fixes the deficiency in 'Get-Command -ParameterType', which returns CommandInfo objects, but doesn't list the names of parameters that have the specified parameter type.
However, because it uses 'Get-Command -ParameterType,' it shares is primary limitation: it gets only parameters in the current session, not in all installed modules.
.PARAMETER ParameterType
Specifies the parameter type. Enter a name or name pattern. Wildcard characters are supported.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.93
Created on: 9/18/2015 4:03 PM
Created by: June Blender
Organization: SAPIEN Technologies, Inc
Filename: Get-ParameterType.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[String]$ParameterType
)
if ($commands = Get-Command -ParameterType $ParameterType)
{
foreach ($command in $commands) {
$parms = $command.ParameterSets.Parameters | where { $_.ParameterType -like "*$ParameterType*" } | Get-Unique
foreach ($parm in $parms)
{
[PSCustomObject]@{ CmdletName = $command.Name; Parameter = $parm.Name; Type = $parm.ParameterType}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment