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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
clum09
Posts: 150
Joined: Thu Apr 24, 2008 9:11 am

Packaged script that uses PSSession

Post by clum09 » Mon Feb 16, 2015 9:14 am

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
Joined: Wed Dec 03, 2014 2:26 pm

Packaged script that uses PSSession

Post by SAPIEN Support Forums » Mon Feb 16, 2015 9:14 am

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: 7049
Joined: Tue May 29, 2007 4:43 pm

Re: Packaged script that uses PSSession

Post by Alexander Riedel » Mon Feb 16, 2015 9:33 am

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
Joined: Thu Apr 24, 2008 9:11 am

Packaged script with utility file in PrimalScript 2012

Post by clum09 » Mon Feb 16, 2015 10:15 am

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.