Board logo

标题: [转载代码] [PowerShell每日技巧]查看远程机器上登录的用户(20140115) [打印本页]

作者: DAIC    时间: 2014-1-20 13:26     标题: [PowerShell每日技巧]查看远程机器上登录的用户(20140115)

In a previous tip we used quser.exe to find the currently logged-on user on the local machine. Here is now a function that also allows us to find the currently logged-on user on a remote machine. As an extra benefit, the returned information is appended by a property called "ComputerName", so when you query multiple machines, you will know where the results came from:
  1. function Get-LoggedOnUser
  2. {
  3.   param([String[]]$ComputerName = $env:COMPUTERNAME)
  4.     $ComputerName | ForEach-Object {
  5.       (quser /SERVER:$_) -replace '\s{2,}', ',' |
  6.         ConvertFrom-CSV |
  7.         Add-Member -MemberType NoteProperty -Name ComputerName -Value $_ -PassThru
  8.   }
  9. }
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/01/15/finding-logged-on-user-on-remote-machine.aspx




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2