![如何检查我登录了域内的哪些机器?](https://linux22.com/image/799093/%E5%A6%82%E4%BD%95%E6%A3%80%E6%9F%A5%E6%88%91%E7%99%BB%E5%BD%95%E4%BA%86%E5%9F%9F%E5%86%85%E7%9A%84%E5%93%AA%E4%BA%9B%E6%9C%BA%E5%99%A8%EF%BC%9F.png)
我经常发现自己通过 RDP 连接到多台机器,并且连接超时,导致我保持登录状态。然后我忘记了我去过哪里,而我的帐户仍然保持登录状态,阻止其他用户访问这些机器。
有没有办法查询域中的用户并列出该用户登录的所有机器?
答案1
您可以使用 PowerShell 查找用户登录的位置。不过,您将需要 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 "[a-z]") -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
您只需根据您的情况进行调整即可。(即计算机和服务器,而不仅仅是服务器)
答案2
有没有办法查询域中的用户并列出该用户登录的所有机器?
不。它不是这样工作的;没有什么比IsLoggedOnTo
附加到 AD 中的用户对象的 ~ 属性更好。登录的用户列表是每台计算机的单独属性/特性,因此您必须单独查询每台计算机。
我 [可能] 会使用 PowerShell 和 TS 管理器/远程桌面服务 MMC 管理单元来解决这个问题...如果不是更容易记住或养成注销的习惯,而不是关闭我的 RDP 窗口的话。
答案3
因此 - 获取域中所有服务器的列表(和/或可能有问题的任何机器)。将其放在名为 servers.txt 的文件中。运行:
for /f %s in (servers.txt) do (echo %s & qwinsta /server:%s )
-- txt 文件示例 --
server1
server2
server3