Open hkelley opened 5 years ago
I've been testing some more and this seems to be a connection clean-up issue. I noticed that the script fails once every time I save it, then runs cleanly until I save the script again. Perhaps O365 cleans up the RunspacePool after my failed attempt and then lets the same command execute again and again.
I'm trying to figure out the WSMan disconnect() and delete() methods but don't know what resource_uri I should provide.
delete(self, resource_uri, resource=None, option_set=None,
selector_set=None, timeout=None):
If there was an error in creating the Runspace Pool that wasn't returned back to pypsrp then it will blindly send the next message which is a receive message with the ShellID it had set. If this ShellID does not exist then you would get the message you put here. Typically on a failure scenario, the server will clean up any resources and hopefully logs the error in the event logs.
I don't have an exchange host or Office 365 account to test this against so I unfortunately can't help you too much. Every execution will generate a unique id for the shell/runspace so there should not be any collisions when it comes to the ID.
I'm trying to figure out the WSMan disconnect() and delete() methods but don't know what resource_uri I should provide.
For PSRP, the resource URI is always http://schemas.microsoft.com/powershell/<configuration_name>
, in your case it would be http://schemas.microsoft.com/powershell/Microsoft.Exchange
. You shouldn't need to use the WSMan methods at all for PSRP as there are analogues to these, e.g. disconnect() ==
pool.disconnect()and
delete() == pool.close()
. Even so, using with RunspacePool(wsman) as pool:
will have Python close the pool for you, unless you want to manually close it you don't have to call this yourself.
Reproduced the problem, and played with it a little bit. I think I know what is the problem. Receive message is sent too fast. It helps to add a little sleep before receive. Maybe better to add retries on receiving.
I have two Python scripts using pypsrp. The first script I created works fine. The second script - even when calling the same cmdlet as the first, returns a ShellID exception.
I get this result: