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!

Code: Select all

# Scans all cmdlets and parameters in a Help file
# Stores the parameter Help text, if it finds any
# Fills in the Help text on parameters with the same name that have no Help text
# Result is saved in HelpFile-new.xml

$HelpFile = 'HelpFile.xml'

[xml]$help = Get-Content -Path $HelpFile

$parmTab = @{}

# Requires 2 runs to be independent of the order in the XML file
1..2 | %{
Write-Host -ForegroundColor Blue "`nRun $_`n"
# For each cmdlet
foreach($cmd in $help.helpItems.command){
Write-Host "$($cmd.details.name)"
# For each parameter
foreach($parm in $cmd.parameters.parameter){
# Do we have help for that parameter
if($parm.description.para)
{
Write-Host -ForegroundColor Green -NoNewline "`t$($parm.name)"
# Remember it
if(!$parmTab.ContainsKey($parm.name))
{
$parmTab.Add($parm.name,$parm.description.para)
}
Write-Host -ForegroundColor Green "`t`t$($parm.description.para)"
}
else
{
# Did we already have a text for this parameter
if($parmTab.ContainsKey($parm.name))
{
Write-Host -ForegroundColor Yellow -NoNewline "`t$($parm.name)`t`t$($parmTab.Item($parm.name))"
# Enter the help text
$parm.description.para = $parmTab.Item($parm.name)
}
else
{
Write-Host -ForegroundColor Red -NoNewline "`t$($parm.name)"
}
Write-Host ''
}
}
}
}

$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.

Who is online

Users browsing this forum: No registered users and 2 guests