Replicate Parameter text in a Help file

Support for all customers who have purchased a PowerShell HelpWriter product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
MASUAC
Posts: 1
Joined: Mon May 04, 2015 11:30 pm

Replicate Parameter text in a Help file

Post by MASUAC » Wed Dec 30, 2015 3:49 pm

While writing Help for a module, the same parameter was used on multiple cmdlets.
Instead of manually replicating the text, I wrote the following short script that does that for you.

The colour code I used on the parameters:
  • Green - parameter Help present
  • Yellow - parameter Help copied
  • Red - no parameter Help found
Verify the generated XML before overwriting or replacing the old file!
  1. # Scans all cmdlets and parameters in a Help file
  2.  
  3. # Stores the parameter Help text, if it finds any
  4.  
  5. # Fills in the Help text on parameters with the same name that have no Help text
  6.  
  7. # Result is saved in HelpFile-new.xml
  8.  
  9.  
  10.  
  11. $HelpFile = 'HelpFile.xml'
  12.  
  13.  
  14.  
  15. [xml]$help = Get-Content -Path $HelpFile
  16.  
  17.  
  18.  
  19. $parmTab = @{}
  20.  
  21.  
  22.  
  23. # Requires 2 runs to be independent of the order in the XML file
  24.  
  25. 1..2 | %{
  26.  
  27.   Write-Host -ForegroundColor Blue "`nRun $_`n"
  28.  
  29. # For each cmdlet
  30.  
  31.   foreach($cmd in $help.helpItems.command){
  32.  
  33.     Write-Host "$($cmd.details.name)"
  34.  
  35. # For each parameter
  36.  
  37.     foreach($parm in $cmd.parameters.parameter){
  38.  
  39. # Do we have help for that parameter
  40.  
  41.       if($parm.description.para)
  42.  
  43.       {
  44.  
  45.         Write-Host -ForegroundColor Green -NoNewline "`t$($parm.name)"
  46.  
  47. # Remember it
  48.  
  49.         if(!$parmTab.ContainsKey($parm.name))
  50.  
  51.         {
  52.  
  53.           $parmTab.Add($parm.name,$parm.description.para)
  54.  
  55.         }
  56.  
  57.         Write-Host -ForegroundColor Green "`t`t$($parm.description.para)"
  58.  
  59.       }
  60.  
  61.       else
  62.  
  63.       {
  64.  
  65. # Did we already have a text for this parameter
  66.  
  67.         if($parmTab.ContainsKey($parm.name))
  68.  
  69.         {
  70.  
  71.           Write-Host -ForegroundColor Yellow -NoNewline "`t$($parm.name)`t`t$($parmTab.Item($parm.name))"
  72.  
  73. # Enter the help text
  74.  
  75.           $parm.description.para = $parmTab.Item($parm.name)
  76.  
  77.         }
  78.  
  79.         else
  80.  
  81.         {
  82.  
  83.           Write-Host -ForegroundColor Red -NoNewline "`t$($parm.name)"
  84.  
  85.         }
  86.  
  87.         Write-Host ''
  88.  
  89.       }
  90.  
  91.     }
  92.  
  93.   }
  94.  
  95. }
  96.  
  97.  
  98.  
  99. $help.Save($HelpFile.Replace('.xml','-new.xml'))

User avatar
juneblender
Posts: 93
Joined: Thu Jul 24, 2014 3:26 pm

Re: Replicate Parameter text in a Help file

Post by juneblender » Wed Dec 30, 2015 4:39 pm

Awesome. Thanks so much.