Weekend Scripter: A Graphical Tool to Explore PowerShell Help

Doctor Scripto

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to explore Help topics.

Microsoft Scripting Guy, Ed Wilson, is here. With the drops of the Windows Management Framework 5.0 (also known as Windows PowerShell 5.0), now is a good time to begin exploring modules, new cmdlets, and so on. It is way cool that Windows PowerShell is largely self-documenting and that it has tools that make it easy to discover features and use them.

Note  The script today works in Windows PowerShell 4.0 and Windows PowerShell 3.0. It does not take advantage of any new features of Windows PowerShell 5.0, but it also works there. It does not work in Windows PowerShell 2.0 because Out-GridView did not contain a –Passthru parameter in that version.

I am spending a lot of time these days playing around with Windows PowerShell 5.0. Because it is not yet released, at times, I need to get old school when it comes to working with the product and rely upon the cmdlet help. There are a few blog posts about it from the Windows PowerShell team and some from various MVPs—but that is about it. Luckily the documentation team has been steadily documenting the product and so I can use help.

So that means that I need to figure out things for myself. I wrote a script that allows me to specify a particular module with the Get-Command cmdlet. I pipe the results to Out-GridView, and then I take the cmdlet I select from Out-GridView and pass it to Get-Help.

It is a pretty useful script, and passing selected items from Out-GridView is a good technique to use because it essentially permits one to make a graphical tool very quickly.

If I wanted to, I could turn this into a function in about 30 seconds—but it is not something I feel like doing at this time. I would specify an input parameter for my module name, and maybe add a parameter to permit only full examples or standard Help output. But like I said, it is not something I feel a real need to do. Using it directly from the Windows PowerShell ISE is fine for what it is.

The first thing I do is specify a variable to hold the module name. This makes it pretty easy to switch modules if I need to do so. Next I use the Get-Command cmdlet to find all the cmdlets and other commands in the specific module. This is shown here:

$m = "hyper-v"

Get-Command -Module $m | 

The next thing I do is use the Select-Object cmdlet to choose a few particular properties from the CmdletInfo object that is returned via the Get-Command cmdlet. I select the name, verb, noun, and the definition parameters:

Select-Object name, verb, noun, definition |

I pipe the object to the Out-GridView cmdlet. I specify a title that includes the module name, and I use the –Passthru parameter. This is important because it pauses the execution of the script, and it waits until I select a cmdlet from the grid view list. After I make a selection, it passes the resulting object down the pipeline. Here is the command:

Out-GridView -Title "Cmdlets from the $m module" -PassThru |

The last thing I do is send the output from Out-GridView to the Get-Help cmdlet. The complete script is shown here:

$m = "hyper-v"

Get-Command -Module $m |

Select-Object name, verb, noun, definition |

Out-GridView -Title "Cmdlets from the $m module" -PassThru |

Get-Help  

As seen here, when I run the script, the output first appears in a grid:

Image of command output

When I press the OK button, the object moves down the pipeline to the Get-Help cmdlet. The output from the Get-Help command appears in the output of the Windows PowerShell ISE. This is shown here where I had selected Add-VMHardDiskDrive from the list in the Out-GridView grid:

Image of command output

And that is all there is to using Out-GridView to assist in exploring Windows PowerShell Help.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

0 comments

Discussion is closed.

Feedback usabilla icon