PoshCode Logo PowerShell Code Repository

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

Generates External MAML Powershell help file for any loaded cmdlet or function

  1. #Requires -version 2.0
  2. #Generates External MAML Powershell help file for any loaded cmdlet or function
  3. #Note: Requires Joel Bennet's New-XML script from http: //www.poshcode.com/1244
  4. #place New-XML in same directory as New-MAML
  5. #Once the XML/MAML file is generated, you'll need to fill in the TODO items and the parameters options
  6. #that are defaulted to false. The position parameter option will need to be changed in the generated MAML also.
  7. #Example Usage to generate a test-ispath.ps1-help.xml file:
  8. #PS C:\Users\u00\bin> $xml = ./new-maml test-ispath
  9. #PS C:\Users\u00\bin> $xml.Declaration.ToString() | out-file ./test-ispath.ps1-help.xml -encoding "UTF8"
  10. #PS C:\Users\u00\bin> $xml.ToString() | out-file ./test-ispath.ps1-help.xml -encoding "UTF8" -append
  11. #For compiled cmdlets place the MAML file in the same directory as the binary module or snapin dll
  12. #For script modules/functions include a reference to the External MAML file for each function
  13. #Note: You can use the same MAML file for multiple functions, example:
  14. #
  15. ## .ExternalHelp C:\Users\u00\bin\test-ispath.ps1-help.xml
  16. ## function test-ipath
  17.  
  18.  
  19. param ($commandName)
  20. $scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)
  21. . $scriptRoot\New-XML.ps1
  22.  
  23. [XNamespace]$helpItems="http://msh"
  24. [XNamespace]$maml="http://schemas.microsoft.com/maml/2004/10"
  25. [XNamespace]$command="http://schemas.microsoft.com/maml/dev/command/2004/10"
  26. [XNamespace]$dev="http://schemas.microsoft.com/maml/dev/2004/10"
  27. $parameters =  get-command $commandName | %{$commandName=$_.Name;$_.parameters} | %{$_.Values}
  28.  
  29. New-Xml helpItems -schema "maml" {
  30.     xe ($command + "command") -maml $maml -command $command -dev $dev {
  31.             xe ($command + "details") {
  32.                 xe ($command + "name") {"$commandName"}
  33.                 xe ($maml + "description") {
  34.                     xe ($maml + "para") {"TODO Add Short description"}
  35.                 }
  36.                 xe ($maml + "copyright") {
  37.                     xe ($maml + "para") {}
  38.                 }
  39.                 xe ($command + "verb") {"$(($CommandName -split '-')[0])"}
  40.                 xe ($command + "noun") {"$(($commandName -split '-')[1])"}
  41.                 xe ($dev + "version") {}
  42.             }
  43.             xe ($maml + "description") {
  44.                 xe ($maml + "para") {"TODO Add Long description"}
  45.             }
  46.             xe ($command + "syntax") {
  47.                 xe ($command + "syntaxItem") {
  48.                 $parameters | foreach {
  49.                     xe ($command + "name") {"$commandName"}
  50.                         xe ($command + "parameter") -require "false" -variableLength "false" -globbing "false" -pipelineInput "false" -postion "0" {
  51.                             xe ($maml + "name") {"$($_.Name)"}
  52.                             xe ($maml + "description") {
  53.                                 xe ($maml + "para") {"TODO Add $($_.Name) Description"}
  54.                             }
  55.                             xe ($command + "parameterValue") -required "false" -variableLength "false" {"$($_.ParameterType.Name)"}
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.             xe ($command + "parameters") {
  61.                 $parameters | foreach {
  62.                 xe ($command + "parameter") -required "false" -variableLength "false" -globbing "false" -pipelineInput "false (ByValue)" -position "0" {
  63.                     xe ($maml + "name") {"$($_.Name)"}
  64.                     xe ($maml + "description") {
  65.                         xe ($maml + "para") {"TODO Add $($_.Name) Description"}
  66.                     }
  67.                     xe ($command + "parameterValue") -required "true" -variableLength "false" {"$($_.ParameterType.Name)"}
  68.                     xe ($dev + "type") {
  69.                         xe ($maml + "name") {"$($_.ParameterType.Name)"}
  70.                         xe ($maml + "uri"){}
  71.                     }
  72.                     xe ($dev + "defaultValue") {}
  73.                 }
  74.                 }
  75.             }
  76.             xe ($command + "inputTypes") {
  77.                 xe ($command + "inputType") {
  78.                     xe ($dev + "type") {
  79.                         xe ($maml + "name") {"TODO Add $commandName inputType"}
  80.                         xe ($maml + "uri") {}
  81.                         xe ($maml + "description") {
  82.                             xe ($maml + "para") {}
  83.                         }
  84.                     }
  85.                         xe ($maml + "description") {}
  86.                 }
  87.             }
  88.             xe ($command + "returnValues") {
  89.                 xe ($command + "returnValue") {
  90.                     xe ($dev + "type") {
  91.                         xe ($maml + "name") {"TODO Add $commandName returnType"}
  92.                         xe ($maml + "uri") {}
  93.                         xe ($maml + "description") {
  94.                             xe ($maml + "para") {}
  95.                         }
  96.                     }
  97.                     xe ($maml + "description") {}
  98.                 }
  99.             }
  100.             xe ($command + "terminatingErrors") {}
  101.             xe ($command + "nonTerminatingErrors") {}
  102.             xe ($maml + "alertSet") {
  103.                 xe ($maml + "title") {}
  104.                 xe ($maml + "alert") {
  105.                     xe ($maml + "para") {}
  106.                 }
  107.             }
  108.             xe ($command + "examples") {
  109.                 xe ($command + "example") {
  110.                     xe ($maml + "title") {"--------------  EXAMPLE 1 --------------"}
  111.                     xe ($maml + "introduction") {
  112.                         xe ($maml + "para") {"C:\PS&gt;"}
  113.                     }
  114.                     xe ($dev + "code") {"TODO Add $commandName Example code"}
  115.                     xe ($dev + "remarks") {
  116.                         xe ($maml + "para") {"TODO Add $commandName Example Comment"}
  117.                         xe ($maml + "para") {}
  118.                         xe ($maml + "para") {}
  119.                         xe ($maml + "para") {}
  120.                         xe ($maml + "para") {}
  121.                     }
  122.                     xe ($command + "commandLines") {
  123.                         xe ($command + "commandLine") {
  124.                             xe ($command + "commandText") {}
  125.                         }
  126.                     }
  127.                 }
  128.             }  
  129.             xe ($maml + "relatedLinks") {
  130.                 xe ($maml + "navigationLink") {
  131.                     xe ($maml + "linkText") {"$commandName"}
  132.                     xe ($maml + "uri") {}
  133.                 }
  134.             }
  135.         }
  136.     }

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