如何使用 PowerShell 获取连接远程桌面用户的计算机?


如果要使用 PowerShell 获取远程计算机上的用户会话,我们需要使用 cmd query 命令。首先,我们将使用以下命令获取本地计算机上的用户会话。

示例

query session

输出

让我们看看查询会话命令支持的其他参数。

示例

PS C:\> query session /?
Display information about Remote Desktop Services sessions.

QUERY SESSION [sessionname | username | sessionid]
              [/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER] [/VM]

sessionname         Identifies the session named sessionname.
username            Identifies the session with user username.
sessionid           Identifies the session with ID sessionid.
/SERVER:servername  The server to be queried (default is current).
/MODE               Display current line settings.
/FLOW               Display current flow control settings.
/CONNECT            Display current connect settings.
/COUNTER            Display current Remote Desktop Services counters information.
/VM                 Display information about sessions within virtual machines.

要获取远程计算机上的会话,我们可以使用/Server:ServerName开关。

示例

query session /server:Test1-win2k12

输出

更新日期:2020 年 12 月 15 日

2 千次以上浏览

开启你的职业生涯

完成课程认证

立即开始
广告
© . All rights reserved.