Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit code for PowerShell session #146

Closed
malthe opened this issue Mar 23, 2022 · 1 comment
Closed

Exit code for PowerShell session #146

malthe opened this issue Mar 23, 2022 · 1 comment

Comments

@malthe
Copy link
Contributor

malthe commented Mar 23, 2022

In order to retrieve the exit code for a PowerShell session (in which the exit command is used), must one instantiate a PSHost instance and provide to the runspace pool?

It seems like PowerShell.poll_invoke and/or PowerShell.end_invoke should also return this exit code, or at least it should be accessible in an easy way.

@jborean93
Copy link
Owner

It's just not possible to get the exit code without first providing a host. The PSRP messages exchanged do not return this value in any shape or form except through the SetShouldExit host call so in order to retrieve it you need to provide a host yourself and implement this method. Technically WSMan itself has an ExitCode field in the ReceiveResponse of the final pipeline message but it does not reflect what was used with exit in the running pipeline (it is always 0). Other transports have no similar transport specific field for this so even if the WSMan one worked you couldn't implement it in a transport agnostic way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants