################################################################################
# Out-HTML - converts module functions or cmdlet help to HTML format
# Minor modification of Vegard Hamar's OUT-HTML to support modules instead of pssnapin's
# Based on Out-wiki by Dimitry Sotnikov (http://dmitrysotnikov.wordpress.com/2008/08/18/out-wiki-convert-powershell-help-to-wiki-format/)
#
# Modify the invocation line at the bottom of the script if you want to document
# fewer command, subsets or snapins
# Open default.htm to view in frameset or index.htm for index page with links.
################################################################################
# Created By: Vegard Hamar
################################################################################
param($outputDir = "./help")
function FixString {
param($in = "")
if ($in -eq $null) {
$in = ""
}
return $in.Replace("&", "&").Replace("<", "<").Replace(">", ">")
}
function Out-HTML {
param($commands = $null, $outputDir = "./help")
$commandsHelp = $commands | sort-object modulename, name | get-help -full
#create an output directory
if ( -not (Test-Path $outputDir)) {
md $outputDir | Out-Null
}
#Generate frame page
$indexFileName = $outputDir + "/index.htm"
#Generate frameset
@'
PowerShell Help
'@ | Out-File "$outputDir/default.htm"
#Generate index
@'
PowerShell Help
'@ | out-file $indexFileName
$SnapIn = ""
foreach ($c in $commandsHelp) {
if ($SnapIn -ne $c.modulename) {
"* " + $c.modulename.Replace(".", " ") + "" | out-file $indexFileName -Append
$SnapIn = $c.modulename
}
}
$SnapIn = ""
foreach ($c in $commandsHelp) {
if ($SnapIn -ne $c.modulename) {
"" | Out-File $indexFileName -Append
$SnapIn = $c.modulename
}
"* $($c.Name)" | out-file $indexFileName -Append
}
#Generate all single help files
$outputText = $null
foreach ($c in $commandsHelp) {
$fileName = ( $outputDir + "/" + $c.Name + ".htm" )
@"
$($c.Name)
$($c.Name)
$($c.synopsis)
Syntax
$(FixString($c.syntax | out-string -width 2000).Trim())
Detailed Description
$(FixString($c.Description | out-string -width 2000))
Related Commands
"@ | out-file $fileName
foreach ($relatedLink in $c.relatedLinks.navigationLink) {
if($relatedLink.linkText -ne $null -and $relatedLink.linkText.StartsWith("about") -eq $false){
" *
$($relatedLink.linkText)" | out-file $fileName -Append
}
}
@"
Parameters
| Name |
Description |
Required? |
Pipeline Input |
Default Value |
"@ | out-file $fileName -Append
$paramNum = 0
foreach ($param in $c.parameters.parameter ) {
@"
| $($param.Name) |
$(FixString(($param.Description | out-string -width 2000).Trim())) |
$(FixString($param.Required)) |
$(FixString($param.PipelineInput)) |
$(FixString($param.DefaultValue)) |
"@ | out-file $fileName -Append
}
"
}" | out-file $fileName -Append
# Input Type
if (($c.inputTypes | Out-String ).Trim().Length -gt 0) {
@"
Input Type
$(FixString($c.inputTypes | out-string -width 2000).Trim())
"@ | out-file $fileName -Append
}
# Return Type
if (($c.returnValues | Out-String ).Trim().Length -gt 0) {
@"
Return Values
$(FixString($c.returnValues | out-string -width 2000).Trim())
"@ | out-file $fileName -Append
}
# Notes
if (($c.alertSet | Out-String).Trim().Length -gt 0) {
@"
Notes
"$(FixString($c.alertSet | out-string -Width 2000).Trim())
"@ | out-file $fileName -Append
}
# Examples
if (($c.examples | Out-String).Trim().Length -gt 0) {
" Examples
" | out-file $fileName -Append
foreach ($example in $c.examples.example) {
@"
$(FixString($example.title.Trim(('-',' '))))
$(FixString($example.code | out-string ).Trim())
$(FixString($example.remarks | out-string -Width 2000).Trim())
"@ | out-file $fileName -Append
}
}
@"
"@ | out-file $fileName -Append
}
@"
"@ | out-file $indexFileName -Append
}
Out-HTML ( get-command | where {$_.modulename -ne $null}) $outputDir