Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

track down why PSSession is in broken state?

Tags:

powershell

I have a remote invocation that keeps breaking and I don't know why, but I also have no idea on how to start investigating this.

The msdn documentation for the PSSession object doesn't seem to have much in it, are there error codes somewhere I can access? How do you go about trying to determine why a PSSession connection was broken?

like image 291
Fred Avatar asked Oct 17 '25 15:10

Fred


1 Answers

I ultimately found the issue, but I also found more info on debugging remoting in powershell.

Here's a video with an explanation: https://www.youtube.com/watch?v=NI_8sJOu_fo&feature=youtu.be&t=33m12s

But in essence

Import-Module PSDiagnostics
Enable-PSWSManCombinedTrace

This starts logging extra information that you can pull up in the windows event log (the video has details). Just enable it on the remote server then pop it open.

For my specific issue, I was updating the password on the server then calling New-PSSession with the new credentials and it apparently was grabbing the old session from cache. I would do more work, but windows would eventually break the connection in the middle of the work.

I had to call Remove-PSSession after finishing the password update, once that was done the subsequent calls to New-PSSession did the right thing.

Basically, I didn't understand the caching mechanisms behind the scenes for the PSSession functionality.

like image 104
Fred Avatar answered Oct 20 '25 07:10

Fred