Pages

12/06/2015

Get short lists of PowerShell cmdlets

 

I write a lot of documentation and I’m always looking for ways to make lists of things easier to read. Long lists of PowerShell commands have always been a problem as they usually should be sorted by the noun. That’s easy enough, but still can consume a lot of space on paper, and still not be too readable, especially when I want to see all the things I can do with a “user”, a “group” or some other object where I have a lot of cmdlets with the same noun.

For example, there are 135 AD cmdlets on my machine. By default Get-Command orders them by verb. But what are all of things I can do with a "user" or "group"?

image

We can sort on the Noun property, but we still get 135 lines of output:

image

 

So here is my solution… and while I'm happy with the results, I think the script is kind of ugly.

Get-Command *-ad* | Group Noun | 
  foreach { $_.Group | 
    foreach -Begin { $x = @{ noun = $_.Group[0].Noun; verb = ""} } 
            -Process { $x.verb += $_.Verb + "," } 
            -End {$x.verb = $x.verb.substring(0,$x.verb.length-1); $x; } } | 
  sort {$_.noun} | select {$_.noun}, {$_.verb} | ft -AutoSize

image

And now I can see at a glance that I can Get, New, Remove and Set. (And not Add or Delete!)

image

 

.

No comments:

Post a Comment

Note to spammers...
Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.