I am attempting to remotely execute a powershell script passing in a object parameter. I have successfully managed to do this, but now I would like to just start the script, disconnect my remote session and have the powershell script continue to execute on the remote machine. Unfortunately I have been unable to do this.
Here is my code so far, this successfully runs the remote powershell script but if I dispose of my session the powershell script also stops executing:
PowerShell ps = PowerShell.Create();
ps.Runspace = _runspace;
ps.AddCommand(scriptPath);
if (scriptParameters != null)
{
foreach (var parameter in scriptParameters)
{
ps.AddParameter(parameter.Key, parameter.Value);
}
}
ps.Invoke();
How can I just kick off the .ps1 script and leave it running even when I disconnect my remote session?