Running Remote Powershell Commandlet that wraps a process exits before completion

核能气质少年 提交于 2019-12-12 04:48:53

问题


I have a custom PowerShell commandlet that I have created in C# that spins up some instances of vstest.console.exe and publishes the test results to a .trx file or to tfs. This commandlet works in isolation when using PowerShell locally.

However when I run the commandlet remotely using v3 PowerShell remoting, The invoke-command completes, but there are 2 issues:

  1. The test run process does not complete as there is no results file published
  2. I do not get the results on the remote console, whereas in the local case they bubble up from the newly started processes

Here is the remote call I used in the remote PowerShell calling script

$j = Invoke-Command -Session $currentPSSession -AsJob -ScriptBlock {
    Add-PSSnapin "IntegrationTestTools"
    Start-IntegrationTests -someotherUnimportantArgs
} | Wait-Job

$results = $j | Receive-Job

from stepping through the script it does indeed wait for the job, however the results are empty.

To note I have setup the remoting as per Keith Hill's post . Also I have setup Wsman with

set-item WSMan:\localhost\Shell\MaxMemoryPerShellMB 0
set-item WSMan:\localhost\Shell\MaxProcessesPerShell 0
set-item WSMan:\localhost\Shell\MaxShellsPerUser 0

So processes and allowed memory should not be limiting this particular exercise.

Any ideas?


回答1:


I thought I'd share in case anyone is unlucky enough to have this happen at some point. If you use credssp as authentication enum when connecting to a remote PowerShell session, your user token is marked as "impersonate", this means that you are part of the NETWORK USER group which means no visibility of WCF named pipes as the SID 5-1-5-2 (more commonly known as the Network SID) is denied access to named pipes. Here's an enlightening article on the subject: KennyW's blog.

The process I was remotely starting with my PowerShell commandlet started child processes that were communicating over named pipes :(
So in the end had to psexec (sysinternals) as system to get that process to execute locally within the remote session. Not elegant but it was all I had available.

Also thanks to Keith Hill for his help with the PowerShell troubleshooting!

My blog article detailing my findings - http://josephkirwin.com/2013/05/06/the-named-pipes-had-a-party-and-imposters-were-not-invited/



来源:https://stackoverflow.com/questions/16323948/running-remote-powershell-commandlet-that-wraps-a-process-exits-before-completio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!