Cache Mechanism

Hey thanks @adam
well, i dont know, pssession dont work at all now :frowning:

i tried to connect to ExchangeOnline, or to a remote computer, i get the following error :

"ErrorRecord": {
      "Exception": "System.Management.Automation.ParentContainsErrorRecordException: An error has occurred which PowerShell cannot handle. A remote session might have ended.",
      "TargetObject": null,
      "CategoryInfo": "ResourceUnavailable: (:) [], ParentContainsErrorRecordException",
      "FullyQualifiedErrorId": "System.Management.Automation.Remoting.PSRemotingDataStructureException",
      "ErrorDetails": null,
      "InvocationInfo": null,
      "ScriptStackTrace": null,
      "PipelineIterationInfo": ""
    },
    "WasThrownFromThrowStatement": false,
    "TargetSite": null,
    "StackTrace": null,
    "Message": "An error has occurred which PowerShell cannot handle. A remote session might have ended.",
    "Data": {},
    "InnerException": {
      "TargetSite": "Void Serialize(System.IO.Stream, System.Object)",
      "StackTrace": "   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)\r\n   at System.Management.Automation.Remoting.RemoteSessionCapability.GetCurrentTimeZoneInByteFormat()\r\n   at System.Management.Automation.RemotingEncoder.GenerateClientSessionCapability(RemoteSessionCapability capability, Guid runspacePoolId)\r\n   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl.HandleNegotiationSendingStateChange()\r\n   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl.HandleStateChanged(Object sender, RemoteSessionStateEventArgs arg)\r\n   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerStateMachine.RaiseStateMachineEvents()\r\n   at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerStateMachine.ProcessEvents()",
      "Message": "BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.",
      "Data": "System.Collections.ListDictionaryInternal",
      "InnerException": null,
      "HelpLink": null,
      "Source": "System.Runtime.Serialization.Formatters",
      "HResult": -2146233067
    }

Maybe you added some restrictions, i dont know. For the very first time i saw in the documentation that you dont support PSSession
We do not support the use of `Enter-PSSession` or `Import-PSSession` .
In any case, thank you for the great work !!

We support New-PSSession but haven’t had success with Enter-PSSession and Import-PSSession.

Are you using the integrated environment when you see this error?

yup

this a simple script (for tests purpose only )
(i have the same behavior, same error, if i do a New-Pssession to some remote computer )

Try {
    Import-module "ExchangeOnlineManagement" -ea stop
    $creds = import-clixml c:\temp\testnit.xml

    connect-exchangeOnline -credential $creds -showbanner:$false -commandName "Get-Mailbox" -ea stop -verbose -debug
    
} catch {
        $_ | convertto-json
}

To launch the script, i click on “Run” then i select the “integrated” env. And the i instantly get the error.
If i use the pwsh env, then it works, but can not store the pssession in a $cache var :upside_down_face: :

Ah, ok. I see the root cause here. I will get this fixed. This should work in 2.0.1.

  "Message": "BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.",
1 Like

Its partialy working on the last nighty @adam !
so just a recap of what we want to achieve at the moment:

  • An automation script, that opens a pssession and store it in a cache variable
  • An Api endpoint, that’s suppose to use the pssession to do some stuff with it (for now, we just do a simple ``invoke-command -session $cache:session -scriptblock {hostname} )

and here are the results from our tests :

What is almost working:

  • If we create a PSSession with an automation script, the pssession is created and stored in the cache variable
  • If we try to do the invoke command from an api endpoint, it’s not working! and after debugging, we find that the connection has been imediatly closed after the automation script ended.

What is working :

  • if we create a PSSession from an api endpoint, and store it in the cache variable, i can access it from another api endpoint without problem and everything works fine !
  • We can access the same cache variable from an automation script ( and doing the invoke command works as expected ! )
    (just to let you know, it works also the exchangeonlinemanagement module ! and i can do an import-pssession ! but we will test this more later )

if i can provide further infos let me know !

Great news!

After some poking around and pondering, I’ve realized this is because with APIs and Dashboards we have a runspace pool that doesn’t close runspaces after actions are taken. This is different with jobs as runspaces are closed immediately. I’ll open an issue for this since it’s going to be a bit of work to make sure this is handled correctly.

1 Like

Hello @adam !
did you have time to look at the issue ?
maybe this has been fixed, i did not do any tests since june so … :frowning:

This hasn’t been resolved. I can push it into the 2.7 release to take a look.

1 Like

Thanks for the update !
that would be extra cool :slight_smile: