Windows PowerShell comes with a lot of help files and documents, but, somehow, my favorite and most frequently used help is the help that I get by typing "Get-Help" in the console.
And I have always wondered why this help is not readily available as a single document, ready to be viewed, searched, and printed. Well, now it is, with this simple Get-Manual script.
This script merges all of the about*.txt files in the C:\Windows\System32\WindowsPowerShell\V1.0 directory and puts them all into one nicely formatted Microsoft Word document (.doc). Once you have this document, you can search it for any specific content. Or, you can print it and enjoy reading it while sitting in your favorite armchair by the fireplace during the long winter evenings :)
---------------------------------------------------------------------
# Get-Manual.ps1
# This script merges the text from all about* help files in the Windows
# PowerShell installation directory ($pshome) into one Microsoft Word
# document (.doc) file and opens the file that was created.
# Set the file name for generated WordML document.
$doc = "AboutHelp.doc"
"Generating MS Word document..."
$sb=new-object system.text.stringbuilder
$null = $sb.Append(@'
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?mso-application progid="Word.Document"?>
<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
<w:styles>
<w:versionOfBuiltInStylenames w:val="4" />
<w:style w:type="paragraph" w:default="on" w:styleId="Normal">
<w:name w:val="Normal" />
<w:rPr>
<w:rFonts w:ascii="Lucida Console" w:h-ansi="Lucida Console" w:cs="Lucida Console" />
<w:sz w:val="24" />
<w:sz-cs w:val="24" />
<w:lang w:val="EN-US" w:fareast="ZH-CN" w:bidi="AR-SA" />
</w:rPr>
</w:style>
<w:style w:type="paragraph" w:styleId="Heading1">
<w:name w:val="heading 1" />
<wx:uiName wx:val="Heading 1" />
<w:basedOn w:val="Normal" />
<w:next w:val="Normal" />
<w:pPr>
<w:pStyle w:val="Heading1" />
<w:keepNext />
<w:spacing w:before="240" w:after="120" />
<w:outlineLvl w:val="0" />
</w:pPr>
<w:rPr>
<w:b />
<w:b-cs />
<w:kern w:val="32" />
<w:sz w:val="32" />
<w:sz-cs w:val="32" />
</w:rPr>
</w:style>
</w:styles>
<w:body>
'@)
# Get all text lines in about* help files.
$filter = "about*.txt"
dir $pshome -filter $filter -recurse | %{
$null = $sb.Append("<w:p><w:pPr><w:pStyle w:val=`"Heading1`" /></w:pPr><w:r><w:t>")
$null = $sb.Append($_)
$null = $sb.Append("</w:t></w:r></w:p>")
get-content $_.FullName | %{
$null = $sb.Append("<w:p><w:r><w:t>")
$null = $sb.Append($_.replace("&", "&").replace("<","<").replace(">",">"))
$null = $sb.Append("</w:t></w:r></w:p>")
}
}
$null = $sb.Append("</w:body></w:wordDocument>")
#Write generated string to document file.
$sb.ToString() | out-file $doc -encoding UTF8
# Open the resulting file in MS-Word.
$null = [System.Diagnostics.Process]::Start("$pwd\$doc")
"Done"
------------------------------------------------------------------------------
Vladimir Averkin
Windows PowerShell Test