Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

Otter - InvalidRunspaceStateException on WinRM servers



  • Hi,

    we’re testing Otter for managing multiple Windows Server and Linux machines in an agentless way (WinRM for Windows, SSH for Linux).

    The Windows servers have WinRM correctly configured, and we can run PowerShell commands successfully from our admin workstation using:

    Invoke-Command -ComputerName WIN001 { Write-Output "Test from $env:COMPUTERNAME" }

    However, when we try to run the same simple script from Otter using the "PowerShell (no agent)" option, the job always fails with a runspace error:

    Unhandled exception: System.Management.Automation.Runspaces.InvalidRunspaceStateException: Cannot perform operation because the runspace is not in the 'Opened' state. Current state of runspace is 'Closed'.
    at System.Management.Automation.PowerShell.CoreInvokeAsync[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings, AsyncCallback callback, Object state, PSDataCollection1 asyncResultOutput) at System.Management.Automation.PowerShell.BeginInvoke[T](PSDataCollection1 input, PSInvocationSettings settings, AsyncCallback callback, Object state)
    at Inedo.Agents.PowerShell.PowerShellExtensions.InvokeInternalAsync(PowerShell ps)
    at Inedo.Agents.PowerShell.PowerShellAgentClient.ExecuteCmdLetAsync(String cmdLet, KeyValuePair2[] args) at Inedo.Agents.PowerShell.PowerShellFileOperationsExecuter.FileExistsAsync(String path) at Inedo.Agents.Hosting.ScriptableRemoteAgentHost.EnsureAgentBinariesAsync(Func1 getPackage, IEnumerable1 extensions, Func2 openExtension, Func1 updateStarted) at Inedo.Otter.Service.Agents.PowerShellAgentConnection.GetRemoteHostAsync() at Inedo.Otter.Service.Agents.PowerShellAgentConnection.TryGetServiceInternalAsync(Type serviceType) at Inedo.Otter.Extensions.Agents.AgentConnection.TryGetServiceAsync(Type serviceType) at Inedo.Otter.Extensions.Agents.ConnectingAgent.GetAgentServiceInternalAsync(Type service) at Inedo.Otter.Extensions.Agents.ConnectingAgent.GetAgentServiceInternal(Type service) at Inedo.Extensibility.Agents.Agent.GetService[TService]() at Inedo.Extensions.Scripting.PowerShell.PSUtil2.ExecuteScript2Async(IPSScriptingOperation operation, IOperationExecutionContext context, Boolean collectOutput, EventHandler1 progressUpdateHandler, String successExitCode, PsExecutionMode executionMode, Boolean preferWindowsPowerShell) in C:\Users\builds\AppData\Local\Temp\InedoAgent\BuildMaster\192.168.44.60\Temp_E578465\Src\Scripting\InedoExtension\PowerShell\PSUtil2.cs:line 131
    at Inedo.Extensions.Scripting.Operations.PowerShell.PSCall2Operation.ExecuteAsync(IOperationExecutionContext context) in C:\Users\builds\AppData\Local\Temp\InedoAgent\BuildMaster\192.168.44.60\Temp_E578465\Src\Scripting\InedoExtension\Operations\PowerShell\PSCall2Operation.cs:line 87
    at Inedo.Otter.Service.PlanExecuter.OtterScriptExecuter.PerformExecution(ActionStatement actionStatement, ILogSink logger, Operation operation, OperationExecutionContext operationContext, OperationInputState hash)
    at Inedo.Otter.Service.PlanExecuter.OtterScriptExecuter.Inedo.ExecutionEngine.Executer.IExecutionHostEnvironment.ExecuteActionAsync(ActionStatement actionStatement, IExecuterContext context)

    Additional details:

    Server status is “Ready,” and OS info is correctly detected.
    Execution Policy on the target servers is Unrestricted.
    We’re using a domain account with local admin rights via GPO.
    We run the same test against multiple Windows servers, all with the same issue.
    In the Windows Event Log, we see entries about creating a ScriptBlock, but no clear error messages.
    Linux shell scripts via SSH run just fine.

    Questions:

    Is there any specific PowerShell version or setting required for Otter's WinRM integration?
    Where can we find more detailed logs on the target server or on the Otter server to debug this issue?

    Thanks for any help you can provide.


  • inedo-engineer

    Hi @alexvanini_5999 ,

    I would try using the Inedo Agent instead; if you are getting this error, it most certainly means that there is some kind of security/hardening/account setting that is blocking WinRM. This is the underlying technology that PS Remoting and the PowerShell-based agent use.

    In this state, it's a real pain to get working - and the Inedo Agent is much more stable, anyway. It will not be "randomly blocked" by a new GPO or Patch Tuesday bug as we've seen a lot with WMI.

    Otherwise, you'll need to scour the web for obscure settings that may have been applied to the server. You may see information logged on the target machine under Windows Event Log under Windows Logs → Application or System related to WinRM.

    It's possible that the domain account lacks needed rights, even though it's a local admin. Sometimes subtle rights (like SeRemoteInteractiveLogonRight, etc.) can block initialization.

    Good luck, let us know what you find!

    Thanks,
    Steve


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation