Page 1 of 1

Parameter use broken on compiled scripts ?

Posted: Mon May 06, 2019 3:09 am
by Aarhus Kommune-1
Hi.

Product, version and build:
PrimalScript 2019 v7.4.127 x64
Powershell Studio 2019 v5.6.162 x64
on
Windows 10 v1809 (17763) x64

Having problems with running compiled scripts (Powershell) with parameters in above mentioned versions of your product, the following code is showing the problem :
  1. param
  2. (
  3.     [Parameter(Mandatory = $true,Position = 1)][string]
  4.     [ValidateSet('Install','Remove')]
  5.     $Action
  6. )
  7.  
  8.     switch($Action){
  9.     'Install' {$RetValue = 'Commandline parameter value = Install'}
  10.     'Remove' {$RetValue = 'Commandline parameter value = Remove'}
  11.     default {$RetValue = 'Commandline parameter value = Unknown'}
  12.     }
  13.     $RetValue | Out-Host
Running from powershell prompt with parameters : .\scriptname.ps1 -Action Install/Remove , it works fine.
Compiled and from commandline with the same parameters , it fails with the following output :

C:\Temp>ParameterTest -Action Install
Line 30: At line:29 char:53
+ [Parameter(Mandatory = $true,Position = 1)][string]
+ ~
Missing closing ')' in expression.

At line:30 char:3
+ [ValidateSet('Install','Remove')]
+ ~
Array index expression is missing or not valid.

At line:30 char:3
+ [ValidateSet('Install','Remove')]
+ ~~~~~~~~~~~
Unexpected token 'ValidateSet' in expression or statement.

At line:32 char:1
+ )
+ ~
Unexpected token ')' in expression or statement.

At line:29 char:2
+ [Parameter(Mandatory = $true,Position = 1)][string]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected attribute 'Parameter'.

This goes for generated executables both in 32bit and 64bit versions and have been testet with following deployment settings :
Microsoft Windows 32 and 64 Bit output files generated
Testet on :
SAPIEN PowerShell V5 Host (Commandline)
SAPIEN PowerShell V3 Host (Commandline)
SAPIEN Script Host (Commandline)
with STA Mode enabled , default manifest embedded and as Current User (being local admin)

Regards Henrik

Re: Parameter use broken on compiled scripts ?

Posted: Mon May 06, 2019 3:35 am
by Alexander Riedel
Make a backup of the current PSBuild.exe in your PrimalScript install folder.
Replace with the file attached here and see if that helps.

Re: Parameter use broken on compiled scripts ?

Posted: Mon May 06, 2019 5:14 am
by Aarhus Kommune-1
Seems to fix it for V3 & V5 commandline option, but an error is still generated for the SAPIEN Script Host (Commandline) option (look below) - maybe i'm using this option wrong , earlier your compilers had an engine running your own flavour of PowerShell - but the manual doesn't explain this mode in details.

C:\Temp>parametertest.exe -Action Install
Error(1): En sætning var ventet : Translation = A sentence was expected

Re: Parameter use broken on compiled scripts ?

Posted: Mon May 06, 2019 7:27 am
by Alexander Riedel
We have no "own flavor of PowerShell", so I am sorry but I do not understand what that would mean.
The SAPIEN Script Host engines are not for PowerShell. They are for ActiveX languages and since they don't say PowerShell (as opposed to those that do say that), we thought that was obvious that they are not for use with PowerShell. :D