@MotoX80 Okay, now i have done some testing and research. It turns out that you are right about it not beeing tied to any window per se. However it is tied to the PS Session. And when that sucker ends it kills the process. This can be solved using the -InDisconnectedSession flag. If i set this in the Invoice-Command call, it does not kill the process. Untill 2 hours :( And i need way more time.
This limit can be reset by using:
$TimeOut = New-PSSessionOption -IdleTimeoutMSec (New-TimeSpan -Days 7).TotalMilliSeconds
-InDisconnectedSession -SessionOption $TimeOut
But i have not been able to set this yet.
ps.AddCommand("Invoke-Command");
ps.AddParameter("ComputerName", Host);
ps.AddParameter("ScriptBlock", filter);
ps.AddParameter("Credential", CreateCredentials());
ps.AddParameter("InDisconnectedSession");
ps.AddParameter("SessionName", "CoolSessionName");
ps.AddParameter("SessionOption", "$psOption");
I dont know how to create this $TimeOut variable and tie it to the parameter SessionOption in my script. Since it is a variable that needs to execute before the Invoke-Command.