我经常发现自己的RDP到多台机器上,并且连接超时,让我login。然后我忘记了自己的位置,并且我的帐户保持login状态,阻止其他用户访问这些机器。
有没有办法查询域中的用户,并列出用户login到的所有机器?
您可以使用PowerShell来查找用户login的位置。 您将需要Active Directory cmdlet:
# Import the Active Directory module for the Get-ADComputer CmdLet Import-Module ActiveDirectory # Query Active Directory for computers running a Server operating system $Servers = Get-ADComputer -Filter {OperatingSystem -like "*server*"} # Loop through the list to query each server for login sessions ForEach ($Server in $Servers) { $ServerName = $Server.Name # When running interactively, uncomment the Write-Host line below to show which server is being queried # Write-Host "Querying $ServerName" # Run the qwinsta.exe and parse the output $queryResults = (qwinsta /server:$ServerName | foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv) # Pull the session information from each instance ForEach ($queryResult in $queryResults) { $RDPUser = $queryResult.USERNAME $sessionType = $queryResult.SESSIONNAME # We only want to display where a "person" is logged in. Otherwise unused sessions show up as USERNAME as a number If (($RDPUser -match "[az]") -and ($RDPUser -ne $NULL)) { # When running interactively, uncomment the Write-Host line below to show the output to screen # Write-Host $ServerName logged in by $RDPUser on $sessionType $SessionList = $SessionList + "`n`n" + $ServerName + " logged in by " + $RDPUser + " on " + $sessionType } } } # When running interactively, uncomment the Write-Host line below to see the full list on screen $SessionList
你只需要调整你的情况。 (即电脑和服务器,而不只是服务器)
有没有办法查询域中的用户,并列出用户login到的所有机器?
不,这不是它的工作原理。 没有什么像附加到AD中的用户对象的IsLoggedOnTo属性。 logging的用户列表是每台计算机的属性/属性,因此您必须单独查询每台计算机。
我会[可能]使用PowerShell和TSpipe理器/远程桌面服务MMCpipe理单元来弄清楚…如果记住或者养成退出的习惯并不容易closures我的RDP窗口。
因此 – 获取域中所有服务器的列表(和/或可能遇到的任何机器)。将其放入一个名为servers.txt的文件中。 跑 :
for /f %s in (servers.txt) do (echo %s & qwinsta /server:%s )
– txt文件示例 –
server1 server2 server3