As some know, I’m busy writing a book. During the course of writing said book, I’ve come across a need to quickly look up the parameters for cmdlets and several particulars thereof. Such was the inspiration for my new favorite function: Get-Parameter. It goes like this:
PS > gpm Get-EventLog ParameterSet: LogName Name Type IsMandatory Pipeline ---- ---- ----------- -------- LogName String True False ComputerName String[] False False Newest Int32 False False InstanceId Int64[] False False Index Int32[] False False EntryType String[] False False Source String[] False False Message String False False AsBaseObject SwitchParameter False False ParameterSet: List Name Type IsMandatory Pipeline ---- ---- ----------- -------- ComputerName String[] False False List SwitchParameter False False AsString SwitchParameter False False
Now gpm is actually a meta-function which I created to customize the output for a particular need for my book. Here’s what Get-Parameter looks like by default.
PS > Get-Parameter -Cmdlet Set-VM | Format-Table Name Type ParameterSet IsMandatory Pipeline ---- ---- ------------ ----------- -------- VM VirtualMachine DefaultSet False True Name String DefaultSet False False MemoryMB Nullable`1 DefaultSet False False NumCpu Nullable`1 DefaultSet False False GuestId String DefaultSet False False AlternateGue... String DefaultSet False False OSCustomizat... OSCustomizat... DefaultSet False False Server VIServer[] DefaultSet False False RunAsync SwitchParameter DefaultSet False False Description String DefaultSet False False VM VirtualMachine SnapshotSet False True Name String SnapshotSet False False Snapshot Snapshot SnapshotSet False True OSCustomizat... OSCustomizat... SnapshotSet False False Server VIServer[] SnapshotSet False False RunAsync SwitchParameter SnapshotSet False False
Instead of posting the code here, I’ve decided to start using the PoshCode script repository and its various evolving features. So, you can find the code at the Get-Parameter listing. Also, here is a direct download link. Should open right in Notepad or however you’ve got that configured.
Update: I’ve updated the link to point to the latest version as of 12/21/08.
Update: (2009-06-30) The ‘gpm’ meta-function got removed from PoshCode at some point, so I’m posting it here for posterity:
function gpm ($Cmdlet) { Get-Parameter $Cmdlet |
ft name,type,is*,pipe* -GroupBy parameterset -AutoSize }
Update (2009-09-24): I’ve changed the script to work standalone instead of as a function.

[...] Hal has a script up called Get-Parameter. [...]
Hey Hal,
Nice script! I tweaked it a little to handle aliases (including aliases to aliases). (v.91)
- Oisin
thanks dude, good work!
I think I’m missing out on something. I’m going through the book (compliments so far!) and reached the section in where this get-parameter script is discussed. The ouput of the scripts keeps on coming back in the book.
My problem now is that the script won’t give me any output at all.
For example: .\Get-Parameter.ps1 get-eventlog
doesn’t show me anything. I’ve tried different kinds of approaches but never got the output as shown in the book.
Please advice in what I am doing wrong here?
Many Thanks!
Kenneth
Kenneth, what you need to do is to dot-source the file first, and then you’ll have a get-parameter function available for use. There’s pros and cons, but I basically decided to distribute the script this way as a part of how I organize smaller scripts into modular pieces which are loaded in every powershell session from my profile. You can read more about dot-sourcing here: http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx#EMBAC
Kenneth,
Have you had any luck with this?. I am having the same issue – no output!
I am running : .\Get-Parameter.ps1 Get-EventLog
Thanks
Brian
Hi Brian,
To be honest I don’t know if I got this to work or if I just skipped this part in the book
Kenneth
Guys, I’ve updated the script to work “standalone” instead of as a function. Download the new version and it should work as you are expecting.
[...] However, there is an easier way. Let’s go back a step and have a look at Get-Random’s second mode. Here is a table showing the two parameter sets (output created with my Get-Parameter script): [...]