Packaged executable not recognizing parameters correctly

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 6 years and 1 month 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.
User avatar
whiggs2
Posts: 38
Last visit: Fri May 13, 2022 11:03 am

Packaged executable not recognizing parameters correctly

Post by whiggs2 »

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:SAPIEN PowerShell Studio 2018 Version 5.5.148
32 or 64 bit version of product: 64-bit
Operating system: Windows 10 Enterprise
Version 1709
OS Build 16299.98
32 or 64 bit OS: 64-bit

*** Please add details and screenshots as needed below. ***
Ok. Please consider the below very simple powershell script:

Code: Select all

param (
	[Parameter(Mandatory = $false)]
	[Switch]$force
)
Add-Type -AssemblyName "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
If ($force)
{
	Write-Host "used force parameter" -ForegroundColor Green
}
Else
{
	Write-Host "Did not use force parameter" -ForegroundColor DarkRed
}
When the script above is compiled into an executable, the executable is unable to correctly identify the presence of the "force" parameter if it is present. See below picture, which shows the output of both the script file and its packaged executable with the "force" parameter:
Image
Executable is not working as expected.

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
Olga_B
Site Admin
Posts: 196
Last visit: Thu Mar 28, 2024 8:34 am

Re: Packaged executable not recognizing parameters correctly

Post by Olga_B »

This is correct behavior. Windows PowerShell cannot convert the string to a type that the Switch parameter accepts.

Check this blog:
https://www.sapien.com/blog/2015/11/30/ ... able-file/
This topic is 6 years and 1 month 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.