Compiled exe and Help

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 38
Joined: Thu Nov 15, 2012 11:01 pm

Compiled exe and Help

Post by CermakPOI »

Product, version and build:
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.160
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0

When compiling a Script to an executable i want to use the Powershell build-in Help function.

My Workaround is in the code below.
Basically i recreate the Script (MyScript.ps1 -> MyScript.exe) Help including Parameter definition into a dummy function (MyScript) so i can print out the help via 'Get-Help -Detailed MyScript' (Where MyScript only shows the duplicated Help from the function.) from inside the compiled script.

The output is correct but i have to copy the Metadata for help creation from the Script to the Function on every change.

Is there an easier way to get Help for a compiled exe in a single file sfolution?

Code: Select all

[CmdletBinding(DefaultParameterSetName = 'help',
			   SupportsShouldProcess = $true)]
# Functions
function myScript{
	#param definition
#region Parameter Handling 
# Write Parameters into Variables
$PSBoundParameters.GetEnumerator() | ForEach-Object {
	$PName = $_.Key
	$PValue = $_.Value
	if (($PValue.length -le 0) -or ($PValue -eq $False)) {
		$PValue = $true
	Write-Host "Parameter: $PName : $PValue" -ForegroundColor green
	$PR = Set-Variable -Name $PName -Value $PValue -Scope global
#endregion Parameter Handling 
if ($help.IsPresent -or ($PsCmdlet.ParameterSetName -eq 'Help')) {
	Get-Help -Detailed MyScript

PS: Searching for the String "Help" in the forums is impossible since it is an ignored string!

User avatar
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Compiled exe and Help

Post by davidc »

SAPIEN Technologies, Inc.

Posts: 14698
Joined: Tue May 22, 2007 9:57 am
Answers: 8
Has voted: 2 times
Been upvoted: 5 times

Re: Compiled exe and Help

Post by jvierra »

Help is defined either by using the built-in help on the script or function or through an external help file. The help will be available in the exe. Just add the help to code and it will be there.