Packaged script that uses PSSession
Posted: 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.
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.
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 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.