Page 1 of 1

Packaged script that uses PSSession

Posted: Mon Feb 16, 2015 9:14 am
by clum09

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

Code: Select all

$scriptBlock = {
		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?


Packaged script that uses PSSession

Posted: Mon Feb 16, 2015 9:14 am
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 ***

Re: Packaged script that uses PSSession

Posted: Mon Feb 16, 2015 9:33 am
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.

Packaged script with utility file in PrimalScript 2012

Posted: Mon Feb 16, 2015 10:15 am
by clum09

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.