完成包装的运行远程Powershell Commandlet会在完成之前退出 [英] Running Remote Powershell Commandlet that wraps a process exits before completion

查看:109
本文介绍了完成包装的运行远程Powershell Commandlet会在完成之前退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#创建的自定义PowerShell Commandlet,它可以启动vstest.console.exe的某些实例,并将测试结果发布到.trx文件或tfs中. 在本地使用PowerShell时,此Commandlet可以独立工作.

但是,当我使用v3 PowerShell远程远程运行Commandlet时,invoke-command完成了,但是存在两个问题:

  1. 由于没有发布结果文件,因此测试运行过程未完成
  2. 我无法在远程控制台上获得结果,但是在本地情况下,它们会从新启动的进程中冒出来

这是我在远程PowerShell调用脚本中使用的远程调用

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

$results = $j | Receive-Job

单步执行脚本确实确实会等待工作,但是结果为空.

请注意,我已经按照解决方案

我想与大家分享一下,以防万一有人不幸在某个时候发生这种情况.如果在连接到远程PowerShell会话时使用credssp作为身份验证枚举,则用户令牌被标记为假冒",这意味着您是NETWORK USER组的一部分,这意味着WCF命名管道作为SID 5-1不可见. -5-2(更通常称为网络SID )被拒绝访问命名管道.这是有关该主题的启发性文章: KennyW的博客.

我从PowerShell Commandlet远程启动的进程启动了通过命名管道进行通信的子进程:(
因此最后必须 psexec (sysinternals)作为系统来获取在远程会话中本地执行的过程.不优雅,但这是我所拥有的全部.

还要感谢 Keith Hill 对PowerShell故障排除的帮助!

我的博客文章详细介绍了我的发现-

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?

解决方案

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/

这篇关于完成包装的运行远程Powershell Commandlet会在完成之前退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆