I am calling Get-Help ... -Full
on various scripts to determine what Parameters are needed to run the script. A dynamic form is then displayed for the user to fill out.
I've noticed that Get-Help
does not always return the same structure, i.e some scripts return
NAME
....
SYNOPSIS
SYNTAX
....
DESCRIPTION
...
PARAMETERS
while others simply return
test2.ps1 [[-foo] <String>] [[-bar] <String>]
I started down a path to retrieve this information from the PSObject
:
PSObject p = (PSObject)results[0].Properties["Parameters"].Value;
foreach (var info in p.Properties)
{
var b = (PSObject[])info.Value;
foreach ( var c in b)
{
Console.WriteLine(c.Properties["name"].Value);
}
}
But this fails with the second type of result.
Is there not a more common way to retrieve this information that I have overlooked?