Powershell

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.

: http://halr9000.com/article/507

2008-06-30 08:20:08

[...] Hal has a script up called Get-Parameter. [...]

2008-06-30 11:55:10

Hey Hal,

Nice script! I tweaked it a little to handle aliases (including aliases to aliases). (v.91)

- Oisin

2008-06-30 12:37:57

thanks dude, good work!

Kenneth
2009-08-06 06:36:28

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

2009-08-07 08:55:50

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

Brian Reck
2009-09-25 07:31:24

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

Kenneth
2009-09-25 07:57:52

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

2009-09-25 13:08:53

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.

2010-01-24 00:47:53

[...] 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): [...]

  • Microblog

  • Recent Posts

  • Recent Comments

  • meta

  • PowerShell Blogroll