I'm running a PowerShell script remotely on my Windows 10 machine. Connected remotely via WinRM + PowerShell Runspace.
However, I'm experiencing issues with the Runspace Disconnect feature
My source machine: Linux
My target machine: Windows 10 x64, running PS version 5.1.18362.752, WinRM enabled, PS Remoting enabled
I've played around and tested PS Runspace Disconnect feature using this C# snippet:
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Net;
using System.Threading.Tasks;
namespace PSDisconnect
{
internal static class Program
{
public static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
}
private static async Task MainAsync()
{
var username = "username"; // < --- set username
var password = "password"; // < --- set password
var ipAddress = "10.10.220.104"; // < --- set ip address
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, ipAddress, 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", new PSCredential(username, new NetworkCredential("", password).SecurePassword));
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Negotiate;
using var runspacePool = RunspaceFactory.CreateRunspacePool(1, 5, connectionInfo);
runspacePool.Open();
var powerShell = PowerShell.Create();
powerShell.RunspacePool = runspacePool;
string scriptContent = "\nfunction Test-GetPSInfo {\nreturn $PSVersionTable.PSVersion\n}\n";
await powerShell.AddScript(scriptContent).InvokeAsync();
var results = await powerShell.AddCommand("Test-GetPSInfo").InvokeAsync();
foreach (var result in results)
{
Console.Out.WriteLine(result.ToString());
}
runspacePool.Disconnect();
}
}
}
This fail to work as expected. I'm getting the following error below stating wrongly that my target machine's PowerShell version is below version 3.0 which is incorrect since my target machine is running PowerShell version 5.1.18362.752
output:
5.1.18362.752
Unhandled exception. System.Management.Automation.PSInvalidOperationException: The Disconnect operation is not supported on the server. The server must be running Windows PowerShell 3.0 or greater for remote runspace pool disconnection support.
at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.BeginDisconnect(AsyncCallback callback, Object state)
at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.Disconnect()
at System.Management.Automation.Runspaces.RunspacePool.Disconnect()
If anyone knows if this is supported or what am I doing wrong - I would appreciate sharing 馃檹
@PaulHigin Does the OMI remoting from Linux to Windows support the disconnect/reconnect feature?
No, the OMI bridge work did not include disconnect/reconnect. There are a lot of WinRM features not implemented, and is one reason why OMI/WinRM is no longer supported (another reason is that the OMI version it is based on is no longer supported).
Currently, only WinRM based PowerShell remoting supports disconnect/reconnect.
@PaulHigin @daxian-dbw
Thanks for your answer.
Does supporting this planned in your roadmap?
If so, can you please provide an estimation?
If not, I can suggest my team's help by supporting the disconnect/reconnect and pushing a PR. The only thing I need is a reference on how to contribute to the OMI bridge
Sorry no. My understanding is that are neither contributing to or accepting contributions to the WinRM/OMI work. @SteveL-MSFT please confirm.
They rejected 2 PRs I submitted to them recently because PowerShell scenarios are not supported by them.
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
Most helpful comment
They rejected 2 PRs I submitted to them recently because PowerShell scenarios are not supported by them.