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.
This topic is 4 years and 11 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.
Locked
User avatar
CermakPOI
Posts: 41
Last visit: Wed Jan 31, 2024 2:57 am

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{
<#
	.SYNOPSIS
		MySynopsis
	
...
#>	
	#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
	return
}

PS: Searching for the String "Help" in the forums is impossible since it is an ignored string!
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Compiled exe and Help

Post by davidc »

[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 4 years and 11 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.
Locked