This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
you can get help in MSH with the command get-help
but because the MSH help is in MAML (XML), you can also directly get the XML help from the files.
so you can format the info as you wish to.
the following example picks up all XML help files in the MSH programdirectory,
and extract the help from the XML file, but only the help I selected.
- First it outputs the filename for each file found (Blue)
- then it reads the file into the $help variable.
- then it gets all the commands from the XML file
- it outputs the Name and Description (in red)
- And then the ExampleNames and Commands (White)
- last it output the Results
# XmlHelp.Msh
# Reading Xml Helpfile Example
# /\/\o\/\/ 2005
ls $MSHHOME\*-Help.xml | foreach {
write-host -fore "blue" $_.Name
$Help = [xml](gc $_.fullName)
$help.helpitems.command | foreach {
write-host -fore "red" $_.details.name;$_.details.description.get_InnerText()
$_.Examples.example | foreach {write-host -fore "White"$_.title.para;write-host -fore "White"$_.code;$_.results}
}
}
As you can see the handling of XML files in MSH is very powerfull,
you can use GM in the resulting XML siblings, and you can just get all the text below with get-innertext.
as this script is just a nice way to get only the examples from the Help,
the fact you can also reach the XML, to for example attach a treeview or datagrid to it to make it browsable (I think I have a VB.NET sample somewhere, that does this would be nice to port, if I have time and can find it.......;-), makes the XML format very powerfull.
but also the way you can "Walk" trough an XML file in MSH
just try it a bit by hand :
MSH>$Help = [xml](gc System.Management.Automation.Security.dll-Help.xml)
MSH>$help
xml helpItems
--- ---------
helpItems
MSH>$help | gm
TypeName: System.Xml.XmlDocument
Name MemberType Definition
---- ---------- ----------
......
MSH>$help.helpitems.command[0].Syntax
SyntaxItem
----------
SyntaxItem
MSH>$help.helpitems.command[0].Syntax.get_innertext()
export-SecureStringSecureStringSystem.Security.SecureStringSecureKeySystem.Security.SecureStringKeySystem.Byte[]
also as more and more files as config files and report files come in the XML format, it's cool to be able to read (and write) them this way (and ofcourse on the internet see the RSS reader examples etc.)
enjoy,
gr /\/\o\/\/