How To Tell If Someone Logged Into A Remote Computer

If you are a sysadmin working in an environment that has tons of domain-joined computers, knowing who’s using which computer can go a long way helping you do your job better.

There is a command-line that works perfectly if you just want to check a handful of computers from time to time.

quser /server:computername

You can even queue up multiple ones in one command to query the info from multiple computers, like this.

quser /server:computer1 & quser /server:computer2 & quser /server:computer3

While the command is extremely useful, it doesn’t help much if you want to use PowerShell.

To check if someone is using a computer on the network in PowerShell,

Get-CimInstance Win32_ComputerSystem -ComputerName $computername | Select -ExpandProperty username

But the drawback is, it returns nothing if someone logs into that computer via RDP. If this doesn’t bother you, you can integrate it into a script that you can run to pull the info from multiple computers.

For example, you can pull a computer list from a specific OU in your AD and check if any of them have been in use before you push out any updates that might interrupt others’ work.

$computers = Get-ADComputer -Filter * -SearchBase "OU=Desktops, OU=Computers, DC=domain_name, DC=local" | Sort-Object Name
ForEach ($computer in $computers) {
    if (Test-Connection $computer.name -Count 2 -Quiet) {
        $user = Get-CimInstance Win32_ComputerSystem -ComputerName $computername | Select -ExpandProperty username
        if ($user) {
            //do something usefule;
        }
    }
}

The script pulls a list of computer from an OU and for each computer in the list, it checks to see if it’s online first. If so, it goes on to check if anyone is using that computer. You can then perform other tasks based on your need.

The post How To Tell If Someone Logged Into A Remote Computer appeared first on Next of Windows.