Packaged script that uses PSSession

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 9 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
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Packaged script that uses PSSession

Post by clum09 »

Hello,

I have a PowerShell script that uses PSSession to start a process on a remote computer. See the code below.

Code: Select all

$scriptBlock = {
		Param($filePath)
		Start-Process -FilePath $filePath
	}
	$Session = New-PSSession -ComputerName $RemoteServer -Credential $Credential
	Invoke-Command -Session $Session -ScriptBlock $scriptBlock -ArgumentList($filePath)

The script will start the remote process on the remote computer and leave the remote process running after the start of the remote execution. The remote process continues to run until it finishes. There is no code in the script to remove the PSSession since doing so will terminate the remote process.

The script works fine when it is not packaged. However, when this script is packaged using either PowerShell V2 or V3 using PrimalScript 2015, the remote process immediately terminates after the execution.

It seems to me that when the packaged script terminates, it also kills the current PSSession. As a result, the remote process will always be terminated immediately after the execution.

How can I packaged this script so that it will leave the PSSession alone so that the remote process continues to run?

Thanks.
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Packaged script that uses PSSession

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, clum09.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PrimalScript 2014, Version & Build: 7.0.46. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Packaged script that uses PSSession

Post by Alexander Riedel »

PSSession requires a hosting process. When you run your script from a shell the script may terminate but the hosting process (the shell) is still running. So that works.

If you package a script, the process ends when you script ends, thus taking all PSSessions down with it.
In order to do what you want to do, you need to wait at the end of the script for the remote process to end.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Packaged script with utility file in PrimalScript 2012

Post by clum09 »

Hello,

I need to package a PowerShell script that requires a utility file to run in PrimalScript 2012.

I added the utility file in the script packager and in Specific folder I added %temp% variable.

In the script, I have the code that points to the %temp% folder to execute this utility file.

However, the packaged script does not extract the utility file to the %temp% location.

Where can this utility file be at or this functionality is broken in PrimaScript 2012?

I know that in PrimalScript 2009, the utility file would be extracted to the %temp% location where it can be executed.

Thanks.
This topic is 9 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.