-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-ValidateSetMembers.ps1
62 lines (49 loc) · 1.63 KB
/
Get-ValidateSetMembers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function Get-ValidateSetMembers {
<#
.SYNOPSIS
Get Allowed parameter values
.DESCRIPTION
Get Allowed parameter values from a given command name
.PARAMETER CommandName
Name of the command. Required
.PARAMETER ParameterName
Name(s) of the parameters to return (leave blank for all)
.EXAMPLE
Get-ValidateSetMembers 'Find-Package' -pn Includes,Type
.EXAMPLE
Get-ValidateSetMembers 'Find-Package'
#>
[CmdletBinding()]
param (
# Name of the command. Required
[Parameter(Mandatory,Position=0)]
[string]
[Alias('cn')]
$CommandName,
# Name(s) of the parameters to return (leave blank for all)
[Parameter(Position=1)]
[AllowNull()]
[string[]]
[Alias('pn')]
$ParameterName
)
[string[]]$CommonParameters =
[System.Management.Automation.PSCmdlet]::CommonParameters +
[System.Management.Automation.PSCmdlet]::OptionalCommonParameters
if ($null -eq $ParameterName) {
$ParameterName = (Get-Command $CommandName).Parameters.Keys |
Where-Object {$CommonParameters -notcontains $_}
}
foreach ($param in $ParameterName) {
$attrib = (
Get-Command $CommandName
).Parameters.$param.Attributes
if ($attrib.ValidValues) {
[pscustomobject][ordered]@{
CommandName = $CommandName
ParameterName = $param
ValidValues = $attrib.ValidValues
}
}
}#END: foreach ($param in $ParameterName) {}
}#END: function Get-ValidateSetMembers {}