Error when running executable generated by Powershell Studio

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 2 years and 3 months 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
jcranecw
Posts: 10
Last visit: Wed Oct 05, 2022 12:22 pm

Error when running executable generated by Powershell Studio

Post by jcranecw »

CwClusterMon.ps1.psbuild
(3.54 KiB) Downloaded 88 times
Product: PowerShell Studio 2021 (64 Bit)
Build: v5.8.196
OS: Windows Server 2019 (64 Bit)
Build: v10.0.19044.0
PowerShell version(s): 5.1.17763.2268

I wrote a service in Powershell that will run fine on it's own as a .ps1 file.
After compiling it in Powershell studio 2021 I get the following error if I run the .exe with a '/i' switch. I also receive the same error if I deploy it as an MSI file. The error shows up in the event log as expected.

Line 79: The term 'that' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

The Line 79 in the error is not from my script and the "that" command it's attempting to find is also not in m y script.
I have upgraded to the latest and greatest. resaved by work and recompiled but the results are the same. I wrote this on my Windows 10 laptop but I'm running it on a Windows Server 2019 VM.
Last edited by jcranecw on Tue Dec 14, 2021 12:28 pm, edited 1 time in total.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Error when running executable generated by Powershell Studio

Post by Alexander Riedel »

Can you please upload the .psbuild file or email it to support@sapien.com?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jcranecw
Posts: 10
Last visit: Wed Oct 05, 2022 12:22 pm

Re: Error when running executable generated by Powershell Studio

Post by jcranecw »

Just attached the .psbuild file to the original post.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Error when running executable generated by Powershell Studio

Post by Alexander Riedel »

The .PsBuild file indicates that the installer settings have no entries for installing a service. Please refer to the "Services" section in the SAPIEN Script Packager.
Since you say the packaged service is not operating even prior to installing, please show the output of the packaging process.
If this shows no errors or warnings, please submit the code you are actually using.
You can do this privately here: https://www.sapien.com/support/upload
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jcranecw
Posts: 10
Last visit: Wed Oct 05, 2022 12:22 pm

Re: Error when running executable generated by Powershell Studio

Post by jcranecw »

I used the create a service template when I wrote the script. My assumption is that basic settings would have been included with the template. The script is attached here and I have uploaded the generated MSI file to the link in the previous post.

Here is the output from the package build...

>> MSI 'C:\Users\jcrane\OneDrive - CloudWave\Documents\SAPIEN\PowerShell Studio\Files\CwClusterMon\CwClusterMon.ps1'
SAPIEN Package and Deploy Tool 4.5 (c) 2005 - 2021 SAPIEN Technologies, Inc.

Processing input files...
Processing settings...
Building MSI file...
MSI file C:\Users\jcrane\OneDrive - CloudWave\Documents\SAPIEN\PowerShell Studio\Files\CwClusterMon\CwClusterMon.msi created.


>> Completed
Attachments
CwClusterMon.ps1
(7.82 KiB) Downloaded 80 times
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Error when running executable generated by Powershell Studio

Post by Alexander Riedel »

Thank you for uploading your files.
I have extracted the code from the service executable in your installer and found the following text.
2021-12-15_9-20-20.png
2021-12-15_9-20-20.png (12.14 KiB) Viewed 2551 times
This explains the error your are seeing.
The code in your exe does not correspond to the script you submitted here in this forum.
From the output you submitted it appears you are rebuilding the installer but not the service executable.

Please understand that
a) building the executable and
b) building the installer
are two distinct different processes.

Build All (F7) usually would combine all necessary steps.

Furthermore, the installer your provided and the .psbuild file indicate that the service executable is not selected as a service for the MSI.
Please make sure you visit the "Service" section in the MSI builder to add the service executable and corresponding settings there.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jcranecw
Posts: 10
Last visit: Wed Oct 05, 2022 12:22 pm

Re: Error when running executable generated by Powershell Studio

Post by jcranecw »

I agree the code in the .exe does not correspond to what's in the script.
I also understand that building the executable and the MSI are separate processes.

Just to verify what I'm doing I ran a build all (see the result below)
I still have the same problem. It looks like the code is being scrambled during the compile.
The statement you pointed out as my problem is inside a comment block. It should not be separated out.

John C.


------ Build started: CwClusterMon, Configuration: x64 ------
Packaging with SAPIEN PowerShell V5 Host (Windows Service) x64
Adding C:\Users\jcrane\OneDrive - CloudWave\Documents\SAPIEN\PowerShell Studio\Files\CwClusterMon\CwClusterMon.ps1
Including external script createjson.ps1
Writing scripts to bin\x64\CwClusterMon.exe
Warning: No custom manifest specified.
Package completed

Processing input files...
Processing settings...
Building MSI file...
MSI file C:\Users\jcrane\OneDrive - CloudWave\Documents\SAPIEN\PowerShell Studio\Files\CwClusterMon\CwClusterMon.msi created.

0 error(s), 1 warning(s)
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Error when running executable generated by Powershell Studio

Post by Alexander Riedel »

Remove this line from your comments
2. The install includes a script called CreateJson.ps1 that can be edited to create the configuration you need

And see what that does please.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jcranecw
Posts: 10
Last visit: Wed Oct 05, 2022 12:22 pm

Re: Error when running executable generated by Powershell Studio

Post by jcranecw »

I did not remove the comment from the file since it's there for a reason. I did however change the comment from a block to individually commented lines and that at least changed the problem.

Now I get what looks like a real Powershell error...
Line 56: Cannot bind argument to parameter 'Path' because it is an empty string.

Once again I was able to copy the script to the system and run it manually be adding a line at the bottom that invokes the Start-MyService function so not sure that this is a script error. The line number in the error does not appear to be a line number from the script. It looks like it's from the executable or the code that actually generated the executable.

I don't have anything that can extract code from the service executable so I'm unable to take a look there.

Any help tracing the error back would be appreciated.

John C.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Error when running executable generated by Powershell Studio

Post by Alexander Riedel »

Please see: https://www.sapien.com/blog/2009/09/02/ ... nvocation/
MyInvocation only works in Microsoft hosts, like the original shell or ISE.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 3 months 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.