Compiled exe and Help

Ask your Windows 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.
Locked
User avatar
CermakPOI
Posts: 35
Joined: Fri Nov 16, 2012 12:01 am
Location: Austria
Contact:

Compiled exe and Help

Post by CermakPOI » Fri Mar 29, 2019 4:47 am

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Compiled exe and Help

Post by davidc » Fri Mar 29, 2019 10:01 am

[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13687
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Compiled exe and Help

Post by jvierra » Fri Mar 29, 2019 11:16 am

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.

Locked