Page 1 of 1

Executable with Switches

Posted: Mon Aug 27, 2018 10:39 am
by rocky.pabillore
To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PoSh Studio 2018,
32 or 64 bit version of product: 64bit
Operating system: win 10 1803
32 or 64 bit OS: 64bit

*** Please add details and screenshots as needed below. ***
So, my question is that I'm trying to create an executable with switches, and with just the \test.ps1 -hello it out puts what I need, but when it is packaged, it does not output anything.


Re: Executable with Switches

Posted: Mon Aug 27, 2018 11:03 am
by mxtrinidad
I'm assuming you got the executable create "Test.exe" and that you got an argument (parameter) created to pass the value.
Again, we don't have much information from you on how the script look like.

So, I can guess the mistake is using the dash '-'. The executable is not a DOS-type command but a .NET PowerShell executable.
Remove the dash and just type the value:

Below is a code I created as an executable:

Code: Select all

	 Created with: 	SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.155
	 Created on:   	8/27/2018 1:49 PM
	 Created by:   	Maximo Trinidad
	 Organization: 	SAPIEN Technologies, Inc.
	 Filename:    Testoutput.ps1 	
		Sample to create an executable to passing a value.

param ([string] $arg1)
	Write-Host "$arg1"

Below is the results:

Code: Select all

PS [21] > pwd

C:\Users\max_t\Documents\SAPIEN\PowerShell Studio\Files\Testexecarg1\bin\x64

PS [28] > .\Testoutput.exe Hello
PS [30] > .\Testoutput.exe -Hello
## -> Displays nothing!
PS [32] >
I hope this help!

Re: Executable with Switches

Posted: Tue Aug 28, 2018 8:23 am
by rocky.pabillore
Param (


if ($hello)
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: is present", 0, "Done", 0x1)

elseif ($no)
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: hello not present", 0, "Done", 0x1)

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Answer is: hello not called", 0, "Done", 0x1)

} I then compile that as a V5 Host (Command Line).. Sorry i forgot to add the source code.

Re: Executable with Switches

Posted: Tue Aug 28, 2018 9:21 am
by mxtrinidad
To be clear, switches are not automatically build in PowerShell executable. You can only pass argument(s) to the existing parameter(s) without the dash.

So, it's possible only if you add more code, which add complexity, in order to expose switches. Even when using Visual Studio then with languages like C# or VB more code still is required.

Now, to keep in simple, just add dash to the argument value, and have the PowerShell code logic handle it.
I think this should be the simplest way.

In the case you may want to display a help for the command, more code will still be needed.


Re: Executable with Switches

Posted: Tue Sep 04, 2018 7:41 am
by davidc
Please refer to the following article on how to handle parameters in an package executable: ... table-file