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, 5.5.154.0
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.
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
Executable with Switches
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Executable with Switches
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:
Below is the results:
I hope this help!
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
<#
.NOTES
===========================================================================
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
===========================================================================
.DESCRIPTION
Sample to create an executable to passing a value.
#>
param ([string] $arg1)
Write-Host "$arg1"
Code: Select all
PS [21] > pwd
Path
----
C:\Users\max_t\Documents\SAPIEN\PowerShell Studio\Files\Testexecarg1\bin\x64
PS [28] > .\Testoutput.exe Hello
Hello
PS [30] > .\Testoutput.exe -Hello
## -> Displays nothing!
PS [32] >
- rocky.pabillore
- Posts: 13
- Last visit: Wed Apr 28, 2021 10:24 am
Re: Executable with Switches
Param (
[switch]$hello,
[switch]$no
)
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)
}
else
{
$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.
[switch]$hello,
[switch]$no
)
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)
}
else
{
$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.
- mxtrinidad
- Posts: 399
- Last visit: Tue May 16, 2023 6:52 am
Re: Executable with Switches
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.
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
Please refer to the following article on how to handle parameters in an package executable:
https://info.sapien.com/index.php/packa ... table-file
https://info.sapien.com/index.php/packa ... table-file
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.