I create PowerShell Remoting session per the following code:
AuthenticationMechanism auth = AuthenticationMechanism.Negotiate;
WSManConnectionInfo ci = new WSManConnectionInfo(
false,
sRemote,
5985,
@"/wsman",
@"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";,
creds);
ci.AuthenticationMechanism = auth;
Runspace runspace = RunspaceFactory.CreateRunspace(ci);
runspace.Open();
PowerShell psh = PowerShell.Create();
psh.Runspace = runspace;
I have two questions, based on this code snippet:
- I need to run this session over a long time; hence I need to make sure that remote session is alive. How can I do this?
- Can I change the duration for which session should be kept alive?