The answer from @mklement0 is very helpful. https://stackoverflow.com/a/42699260/447901
I wanted to write a script that will produce all Github configuration settings. The PowerShellForGitHub module function Get-GitHubConfiguration only reports one at a time and you must already know the name of the setting. The settings supported vary across versions. This code gets the setting names based on the ValidateSet() for the $Name parameter and produces them all.
The question is... Is it important to test that the Attribute is of type [System.Management.Automation.ValidateSetAttribute]? What other type might it be?
Both of the $Names =
lines produce the same array.
[CmdletBinding()]
#$Names = (Get-Command -Name 'Get-GitHubConfiguration').Parameters.Name.Attributes.ValidValues
$Names = ((Get-Command -Name 'Get-GitHubConfiguration').Parameters.Name.Attributes |
Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }).ValidValues
foreach ($Name in $Names) {
[PSCustomObject]@{
Name = $Name
Value = Get-GitHubConfiguration -Name $Name
}
}