Page 1 of 1

Compiled exe and Help

Posted: Fri Mar 29, 2019 4:47 am
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!

Re: Compiled exe and Help

Posted: Fri Mar 29, 2019 10:01 am
by davidc
[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]

Re: Compiled exe and Help

Posted: Fri Mar 29, 2019 11:16 am
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.