Created
June 16, 2016 15:45
-
-
Save juneb/6cbc1eba77186514512d0931caaa232c to your computer and use it in GitHub Desktop.
Gets command parameters that have the specified parameter type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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