/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" MSH prompt-User function with Help "," Monad IRC Bot "," Getting performanceMonitor info from Monad "," Monad -and More bytes with -band = shorter script "," Tip from Monad "," MSH AD querying with .NET 2.0 framework "," get AD user allowed Logonhours from MSH "," MSH Show-Byte Function "," Let monad "drop" some chars "," getting an Inputbox in MOnad "," ")

Tuesday, December 13, 2005


Read the raw Monad XML helpfiles

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)

xml                                                                   helpItems
---                                                                   ---------

MSH>$help | gm

    TypeName: System.Xml.XmlDocument

Name                        MemberType            Definition
----                        ----------            ----------



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.)


gr /\/\o\/\/

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?