Playing Around with XML Files Using PowerShell Without Screwing them Up

For example, let’s use a file we can all play with because it comes with PowerShell. Let’s use a help file from which cmdlet help is generated when you use the Get-Help cmdlet. The basic help files are located in the language dependent directory under the PowerShell home directory. In my case, I am using the US English system, so I’ll find the help files when I run the following command in my PowerShell session:

dir $PShome\en-us\*.xml

Which returns the following list of files for my system:

    Directory: C:\Windows\System32\WindowsPowerShell\v1.0\en-us

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         6/10/2009   3:37 PM     160510 Microsoft.PowerShell.Commands.Diagnostics.dll-Help.xml
-a---         6/10/2009   3:22 PM    1957661 Microsoft.PowerShell.Commands.Management.dll-Help.xml
-a---         6/10/2009   3:22 PM    1602040 Microsoft.PowerShell.Commands.Utility.dll-Help.xml
-a---         6/10/2009   3:22 PM      15869 Microsoft.PowerShell.ConsoleHost.dll-Help.xml
-a---         6/10/2009   3:22 PM     154493 Microsoft.PowerShell.Security.dll-Help.xml
-a---         6/10/2009   3:37 PM     538884 Microsoft.Wsman.Management.dll-Help.xml
-a---         6/10/2009   3:22 PM    1268150 System.Management.Automation.dll-Help.xml

Now, I’m going to pick the last file in the list, System.Management.Automation.dll-Help.xml

Why that one? Well, I cheated. I already know this is the help file that contains the help text for the basic PowerShell commands, like Get-Help. But all the files are structured the same way. Once I show you how to walk through one help file, you can do the same thing for any of the help files. Even for modules or snap-ins. That’s the beauty of XML files. They're all structured the same way.

We’ve found some files that we can look at together because these files come with PowerShell 2.0. And now that I know you can follow along in the coming blog entries here’s what I’m going to do:

  1. Read a PowerShell help file using Get-Content as Plain Text (Reading the file part 1 of 2)
  2. Read a PowerShell help file using Get-Content as XML (Reading the file part 2 of 2)
  3. Navigate through the Lower Depths of the PowerShell Help File
  4. Now, let’s start automating parsing the PowerShell help file