Private/Add-SpecModuleHelp.ps1
function Add-SpecModuleHelp { <# .SYNOPSIS Generates and adds help content for a specified PowerShell module. .DESCRIPTION The Add-SpecModuleHelp function creates help content for a PowerShell module and adds it to the module's path. It generates a module help text that includes the module's short description and prepares a help file named "about_ModuleName.help.txt" within the module's "en-US" subdirectory. .PARAMETER moduleName Specifies the name of the module. .PARAMETER modulePath Specifies the path to the module's root directory. .PARAMETER moduleShortDescription Specifies a short description of the module. .EXAMPLE Add-SpecModuleHelp -moduleName "MyModule" -modulePath "C:\Path\To\Module" -moduleShortDescription "This module provides various utilities for XYZ." This example generates and adds help content for a module named "MyModule" located at "C:\Path\To\Module". .NOTES Author : owen.heaume Version : 1.1 #> [cmdletbinding()] param ( [parameter (mandatory = $true)] [string]$moduleName, [parameter (mandatory = $true)] [string]$modulePath, [parameter (mandatory = $true)] [string]$moduleShortDescription ) begin { $fullModulePath = Join-Path $modulePath $moduleName # .psm1 module loader code $moduleHelpText = @" TOPIC about_$moduleName SHORT DESCRIPTION $moduleShortDescription LONG DESCRIPTION EXAMPLES KEYWORDS SEE ALSO "@ } process { # Create module help file try { $fullModulePath = join-path "$ModulePath\$modulename" $modulename #write-host "$fullModulePath" -ForegroundColor Green $enUSDir = Join-Path $fullModulePath "en-US" $fileName = "about_$moduleName.help.txt" Write-verbose "Creating module help file: $enUSDir\$fileName" new-item -path $enUSDir -Name $fileName -ItemType File | Out-Null -ea stop -ev x Set-Content -Path (Join-Path $enUSDir $fileName) -Value $moduleHelpText -ea Stop -ev x return $true } catch { write-warning "Unable to create module help file: $enUSDir\$fileName" Write-warning "The error was $x" return $false } } } |