Reputation: 2055
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:
Upvotes: 3
Views: 1871
Reputation:
Since you have two questions, I have two headings for separate responses.
You can examine the state of the PowerShell Runspace
object by using the State
property, which points to a value of the RunSpaceState
.NET enumeration:
var IsOpened = runspace.RunspaceStateInfo.State == RunspaceState.Opened;
If you want to set the IdleTimeout
for the PowerShell session, then you need to:
PSSessionOption
classIdleTimeout
propertySetSessionOptions()
method on the WSManConnectionInfo
objectCode:
var option = new PSSessionOption(); // Create the PSSessionOption instance
option.IdleTimeout = TimeSpan.FromMinutes(60); // Set the IdleTimeout using a TimeSpan object
ci.SetSessionOptions(option); // Set the session options on the WSManConnectionInfo instance
Upvotes: 3