Replicate Parameter text in a Help file

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
MASUAC
Posts: 1
Last visit: Thu Nov 30, 2017 6:18 am

Replicate Parameter text in a Help file

Post by MASUAC »

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. # Stores the parameter Help text, if it finds any
  3. # Fills in the Help text on parameters with the same name that have no Help text
  4. # Result is saved in HelpFile-new.xml
  5.  
  6. $HelpFile = 'HelpFile.xml'
  7.  
  8. [xml]$help = Get-Content -Path $HelpFile
  9.  
  10. $parmTab = @{}
  11.  
  12. # Requires 2 runs to be independent of the order in the XML file
  13. 1..2 | %{
  14.   Write-Host -ForegroundColor Blue "`nRun $_`n"
  15. # For each cmdlet
  16.   foreach($cmd in $help.helpItems.command){
  17.     Write-Host "$($cmd.details.name)"
  18. # For each parameter
  19.     foreach($parm in $cmd.parameters.parameter){
  20. # Do we have help for that parameter
  21.       if($parm.description.para)
  22.       {
  23.         Write-Host -ForegroundColor Green -NoNewline "`t$($parm.name)"
  24. # Remember it
  25.         if(!$parmTab.ContainsKey($parm.name))
  26.         {
  27.           $parmTab.Add($parm.name,$parm.description.para)
  28.         }
  29.         Write-Host -ForegroundColor Green "`t`t$($parm.description.para)"
  30.       }
  31.       else
  32.       {
  33. # Did we already have a text for this parameter
  34.         if($parmTab.ContainsKey($parm.name))
  35.         {
  36.           Write-Host -ForegroundColor Yellow -NoNewline "`t$($parm.name)`t`t$($parmTab.Item($parm.name))"
  37. # Enter the help text
  38.           $parm.description.para = $parmTab.Item($parm.name)
  39.         }
  40.         else
  41.         {
  42.           Write-Host -ForegroundColor Red -NoNewline "`t$($parm.name)"
  43.         }
  44.         Write-Host ''
  45.       }
  46.     }
  47.   }
  48. }
  49.  
  50. $help.Save($HelpFile.Replace('.xml','-new.xml'))
User avatar
juneblender
Posts: 93
Last visit: Thu Mar 30, 2017 8:54 am

Re: Replicate Parameter text in a Help file

Post by juneblender »

Awesome. Thanks so much.
This topic is 8 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.