PoshCode Logo PowerShell Code Repository

Out-Wiki (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/526"></script>download | new post

Out-Wiki – converts cmdlets help to media wiki (wikipedia) format
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 to point to your
PowerShell snapin, and change the preface in the “generate index” section

  1. ################################################################################
  2. # Out-Wiki - converts cmdlets help to media wiki (wikipedia) format
  3. # http://dmitrysotnikov.wordpress.com/2008/08/18/out-wiki-convert-powershell-help-to-wiki-format/
  4. # Modify the invocation line at the bottom of the script to point to your
  5. # PowerShell snapin, and change the preface in the "generate index" section
  6. ################################################################################
  7. # (c) Dmitry Sotnikov, http://dmitrysotnikov.wordpress.com
  8. ################################################################################
  9.  
  10. function Out-Wiki {
  11.    param($commands = $null, $outputDir = "./help")
  12.  
  13.    $commandsHelp = $commands | sort-object noun | get-help -full
  14.  
  15.    #create an output directory
  16.    if ( -not (Test-Path $outputDir)) {
  17.                 md $outputDir | Out-Null
  18.    }
  19.    
  20.    #Generate frame page
  21.    $indexFileName = $outputDir + "/index.txt"
  22.  
  23.  
  24.    #Generate index
  25. @'
  26. The ActiveRoles Management Shell for Active Directory is an Active Directoryspecific
  27. automation and scripting shell that provides a command-line
  28. management interface for administering directory data either via Quest
  29. ActiveRoles Server or by directly accessing Active Directory domain
  30. controllers. The ActiveRoles Management Shell is built on Microsoft Windows
  31. PowerShell technology.
  32.  
  33. The following cmdlets are currently in the package:
  34.  
  35. '@  | out-file $indexFileName
  36.  
  37.    foreach ($c in $commandsHelp) {
  38.       "* [[$($c.Name)]]"   | out-file $indexFileName -Append
  39.    }
  40.  
  41.    '[[Category:QAD cmdlets reference]]'  | out-file $indexFileName -Append
  42.    
  43.    #Generate all single help files
  44.    $outputText = $null
  45.    foreach ($c in $commandsHelp) {
  46.       $fileName = ( $outputDir + "/" + $c.Name + ".txt" )
  47.  
  48.           "$($c.synopsis)"  | out-file $fileName
  49.      
  50.       # Syntax
  51.       "== Syntax =="  | out-file $fileName -Append
  52.       "<code>$(($c.syntax | out-string  -width 2000).Trim())</code>"  | out-file $fileName -Append
  53.  
  54.       # Detailed Description
  55.       "== Detailed Description =="  | out-file $fileName -Append
  56.           "$($c.Description  | out-string  -width 2000)"  | out-file $fileName -Append
  57.    
  58.       # Related Commands
  59.       "== Related Commands =="  | out-file $fileName -Append
  60.       foreach ($relatedLink in $c.relatedLinks.navigationLink) {
  61.          if($relatedLink.linkText -ne $null -and
  62.             $relatedLink.linkText.StartsWith("about") -eq $false){
  63.             "* [[$($relatedLink.linkText)]]"  | out-file $fileName -Append        
  64.          }
  65.       }
  66.    
  67.       # Parameters
  68.       "== Parameters =="  | out-file $fileName -Append
  69. @'
  70. {| class="wikitable" border=1
  71. |-
  72. !Name
  73. !Description
  74. !Required?
  75. !Pipeline Input
  76. !Default Value
  77. '@   | out-file $fileName -Append
  78.  
  79.       $paramNum = 0
  80.       foreach ($param in $c.parameters.parameter ) {
  81.          "|-"  | out-file $fileName -Append
  82.          "!$($param.Name)"  | out-file $fileName -Append
  83.          "|$(($param.Description  | out-string  -width 2000).Trim())"  | out-file $fileName -Append
  84.          "|$($param.Required)"  | out-file $fileName -Append
  85.          "|$($param.PipelineInput)"  | out-file $fileName -Append
  86.          "|$($param.DefaultValue)"  | out-file $fileName -Append
  87.       }
  88.       "|}"  | out-file $fileName -Append
  89.    
  90.       # Input Type
  91.           if (($c.inputTypes | Out-String ).Trim().Length -gt 0) {
  92.                 "== Input Type =="  | out-file $fileName -Append
  93.                 "$(($c.inputTypes  | out-string  -width 2000).Trim())"  | out-file $fileName -Append
  94.           }
  95.    
  96.       # Return Type
  97.           if (($c.returnValues | Out-String ).Trim().Length -gt 0) {
  98.                 "== Return Values =="  | out-file $fileName -Append
  99.                 "$(($c.returnValues  | out-string  -width 2000).Trim())"  | out-file $fileName -Append
  100.           }
  101.          
  102.       # Notes
  103.          if (($c.alertSet | Out-String).Trim().Length -gt 0) {
  104.       "== Notes =="  | out-file $fileName -Append
  105.       "$(($c.alertSet  | out-string -Width 2000).Trim() )"  | out-file $fileName -Append
  106.         }
  107.    
  108.       # Examples
  109.          if (($c.examples | Out-String).Trim().Length -gt 0) {
  110.       "== Examples =="  | out-file $fileName -Append     
  111.           foreach ($example in $c.examples.example) {
  112.               "==== $($example.title.Trim(('-',' ')))===="  | out-file $fileName -Append
  113.               "<pre>$(($example.code | out-string ).Trim())</pre>"  | out-file $fileName -Append
  114.               "$(($example.remarks | out-string -Width 2000).Trim())"  | out-file $fileName -Append
  115.                
  116.           }
  117.           }
  118.          
  119.       '[[Category:QAD cmdlets reference]]'   | out-file $fileName -Append
  120.    }
  121. }
  122.  
  123. Out-Wiki (Get-Command -PSSnapin Quest.ActiveRoles.ADManagement) "c:\Temp\QADHelp"

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me