如何检查我在域中登录了哪些机器?

Sio*_*Sio 5 rdp active-directory mstsc

我经常发现自己的 RDP 进入多台机器并且连接超时,让我保持登录状态。然后我忘记了我去过哪里,我的帐户保持登录状态,阻止其他用户访问这些机器。

有没有办法查询域上的用户并列出该用户登录的所有机器?

col*_*ete 5

您可以使用 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
Run Code Online (Sandbox Code Playgroud)

您只需要根据您的情况进行调整即可。(即计算机和服务器,而不仅仅是服务器)