如何使用 script/powershell/... 确定远程机器上的会话 ID 以与 psexec -i 一起使用? [英] How to determine the session id on remote machine for usage with psexec -i using script/powershell/...?

查看:27
本文介绍了如何使用 script/powershell/... 确定远程机器上的会话 ID 以与 psexec -i 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个脚本或 powershell 命令,它能够确定远程机器上特定登录用户的会话 ID,稍后用作 psexec -i 执行远程 gui 进程的参数该用户在远程计算机上的会话.

I am in need of a script or powershell command that will be able to determine the session id of a specific logged in user on remote machine, to be later used as parameter to the psexec -i execution of remote gui process on that session of that user on the remote machine.

到目前为止我设法使用

psexec \remoteMachine -u user -p pswrd query session

获取远程机器上的会话列表:

to get list of sessions on the remote machine:

SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
console                                     0  Conn    wdcon
rdp-tcp#919       user                     1  Active  rdpwd
rdp-tcp#916       user                     3  Active  rdpwd

所以我想我可以以某种方式隔离所需的 id 并使用它 - 但还没有设法做到这一点

so i guess i could somehow isolate the needed id and use it - but haven't managed to do that yet

有什么想法吗?也许其他 - 更简单的方法?

Any ideas? Maybe other - simpler ways?

感谢您的帮助.

推荐答案

使用 PSterinalServices powershell 模块,您可以获得用户会话和 ID.
该模块可以在这里找到:http://code.msdn.microsoft.com/PSTerminalServices

With the PSTerinalServices powershell module you can get the user sessions and IDs.
The module can be found here: http://code.msdn.microsoft.com/PSTerminalServices

PS > Get-TSSession -UserName user1 -ComputerName pc1 | select UserName,SessionId

UserName SessionId
-------- ---------
User             1

这篇关于如何使用 script/powershell/... 确定远程机器上的会话 ID 以与 psexec -i 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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