Powershell 查询远程电脑的在线用户 7


在先前的技巧中我们使用Quser.exe查询到了本地电脑当前的登录用户,用下面这个函数也能获取远程电脑的当前登录用户,同时附加了它的计算机名,所以当你查询多台电脑时将知道结果从哪里来。

function Get-LoggedOnUser
{
  param([String[]]$ComputerName = $env:COMPUTERNAME)

    $ComputerName | ForEach-Object {
      (quser /SERVER:$_) -replace '\s{2,}', ',' | 
        ConvertFrom-CSV |
        Add-Member -MemberType NoteProperty -Name ComputerName -Value $_ -PassThru
  }
}

下面一个简单的实例演示,查询本地系统和一台远程电脑:

2014_2D00_01_2D00_20.2

 

 

 

 

 

原文地址:Finding Logged-On User on Remote Machine

本文链接: https://www.pstips.net/finding-on-user-on-remote-machine.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

回复 penshine 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

7 条评论 “Powershell 查询远程电脑的在线用户

  • 荔非苔

    Powershell 查看远程计算机已经登录的用户名:之前没仔细看,原来这个IDLE和Logon Time属性也很实用啊:USERNAME : mosserSESSIONNAME : rdp-tcp#0ID : 2STATE : ActiveIDLE TIME : 18LOGON TIME : 5/8/2014 2:14 PMComputerName : mosser-vm

  • 荔非苔

    不需要cmd,quser本身就是可执行程序。

    $pro=New-Object System.Diagnostics.Process
    $pro.StartInfo.FileName="quser.exe"
    $pro.StartInfo.RedirectStandardOutput=$true
    $pro.StartInfo.UseShellExecute=$false
    $pro.Start()
    $pro.WaitForExit()