NOTE: Wassim and the PowerShell team have released an updated version of this tool: http://blogs.msdn.com/b/powershell/archive/2011/02/24/cmdlet-help-editor-v2-0-with-module-support.aspx There is no real need to complete the exercise below unless you wish to do if for educational purposes.
Reflector recently went from a free product to a commercial one which caused quite an uproar in the community. My perception is that most people only use Reflector in very particular circumstances. I use Reflector all the time. In my opinion Reflector is worth every penny of that $35 dollars. Hopefully I can win a copy though. Although I work at Quest, I am not on the PowerGUI team and have never had access to their source code. Thus the only way I would have been able to create PowerGUI VSX is with Reflector. This post will be about the Power of Reflector.
The PowerShell Cmdlet Help Editor
Back in 2007, Wassim Fayed released the Cmdlet Help Editor. It is a tool that allows users to create cmdlet help for their snap-ins. It worked great! But when PowerShell v2.0 came out there was no word of any type of update. Modules are completely unsupported using the tool. Here is how to get the help editor to support modules.
What you’ll need:
Open Reflector and add the Reflexil.Reflector.dll to the loaded add-ins. This will give you the ability to view and modify the IL code that makes up .NET assemblies. Now you’ll need to load up the HelpEditor.exe.
Modify the LoadRegisteredPsSnapins method.
Change the first instruction’s operand to “get-module -listavailable”. Then remove the instructions for loading the Microsoft snapins. You’ll be left with the above instructions.
Modify the MyPipelineInvocation method to retrieve only the name from the returned command so that we don’t get any exceptions when trying to grab properties that don’t exist.
What I’ve done is deleted the instructions 35-93. Thus we are left with only the retrieval of the “Name” property.
Modify the LoadPsSnapin method to import modules rather than load snap-ins.
I’ve removed the attempt to load the Snap-In because this will fail because PsSnapinName will be the name of the module. You’ll need to delete instructions 123-171. I’ve also changed the command from simply Get-Command to an Import-Module and Get-Command pipeline.
Here are the instructions for creating the pipeline.
Once you complete these modifications you’ll have to save the new module by selecting the HelpEditor.exe node in Reflector and clicking Save As. Place the patched executable back in the installation directory and load it up.
You’ll see all the modules installed on your system:
Selecting one of the modules and clicking New Help File will interrogate the module just as the original did with snap-ins:
There you have it. A help editor for modules! I’m not going to post the patched exe here because I want to get approval to do so first.