Avatar of Lennart Giaccotto
Lennart Giaccotto

asked on 

Script or program to see who is logged in where in the complete domain

I am in search of a script or (free) program which can tell me who is logged in in one of our systems in the domain. i see a lot of scripts that can tell me for just one system but i want to see it for all systems so i can see if a user is still logged in somewhere
Active DirectoryPowershell* auditing

Avatar of undefined
Last Comment
Lennart Giaccotto
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

How many systems? Something that can say who is logged on everywhere is almost always a problem of scale. If you have 30 computers, it's easy. If you have 5000, the burden of checking is a bit daft.
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Oh and I used to use this, long ago, for a mid-size (500 to 1000 systems) domain to give me an overview:

http://blogs.msmvps.com/kwsupport/2005/02/24/lazy-mans-way-to-track-user-logonlogoff/

It has some limitations, it doesn't trigger when a user is connected via a VPN client for example. A lot depends on the size and nature of your domain.
Avatar of Lennart Giaccotto
Lennart Giaccotto

ASKER

Thanks for the comment Chris. We are talking about +/- 200 systems. What is am looking for is a program or script who tells me who is logged on at this right moment. We already have auditing which tells me when someone logged in or logged of. i need something like
query user /server:$SERVER

Open in new window

but for all domain members at once without me having to give up the names of the domain members
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

200... it won't be amazingly fast, this makes the request of 50 computers at once. Once they've all finished you'll get a list (from the Receive-Job line).

The list of computers is pulled from Active Directory. It'll include servers at the moment, you might want a better filter.
$threadLimit = 50

Get-ADComputer -Filter { Enabled -eq $true } | ForEach-Object {
    while ((Get-Job -State Running | Measure-Object).Count -ge $threadLimit) {
        Start-Sleep -Seconds 5
    }
    $null = Start-Job -ArgumentList $_.Name -ScriptBlock {
        Get-CimInstance Win32_ComputerSystem -ComputerName $args[0] -Property Name, UserName
    }
}

Get-Job | Wait-Job | Receive-Job | Select-Object Name, UserName
# Tidy up
Get-Job | Remove-Job

Open in new window

Avatar of Ajit Singh
Ajit Singh
Flag of India image

Powershell script to see currently logged in users (domain and machine) + status (active, idle, away):
http://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status

How to track user logon sessions using event log:
https://community.spiceworks.com/how_to/130398-how-to-track-user-logon-sessions-using-event-log

Track users logon events across the company domain:
https://community.spiceworks.com/how_to/2809-track-users-logon-events-across-the-company-domain

Hope this helps!
Avatar of Lennart Giaccotto

ASKER

Hi Kevin, Thank you for your post. I already looked at this one. The function sounds promising but when i run it i get no output at all.

@crhis: Thanks for the Script. It seems to work :-). The output is a bit cloudy though. Is it possieble to save the output to a txt file so i can search it and maybe to not show the errors?
WinRM cannot process the request. The following error occurred while using Kerberos authentication: Cannot find the computer <COMPUTERNAME>. Verify that the computer exists on the network and that the name provided is spelled correct
ly.
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Upgraded the error handling. It should tell you if something isn't around now. Added two output options (gridview and file).
$threadLimit = 50

Get-ADComputer -Filter { Enabled -eq $true } | ForEach-Object {
    while ((Get-Job -State Running | Measure-Object).Count -ge $threadLimit) {
        Start-Sleep -Seconds 5
    }
    $null = Start-Job -ArgumentList $_.Name -ScriptBlock {
        try {
            Get-CimInstance Win32_ComputerSystem -ComputerName $args[0] -Property Name, UserName -ErrorAction Stop |
                Add-Member State 'OK' -PassThru
        } catch {
            [PSCustomObject]@{
                Name     = $_.Name
                UserName = ''
                State    = 'Failed ({0})' -f $_.Exception.Message.Trim()
            }
        }
    }
}

# Variable assignment to show different output options
$report = Get-Job | Wait-Job | Receive-Job | Select-Object Name, UserName
# Tidy up
Get-Job | Remove-Job

# GridView
$report | Out-GridView
# File
$report | Export-Csv ComputersAndUsers.csv -NoTypeInformation

Open in new window

Avatar of Lennart Giaccotto

ASKER

Powershell on my server seems to crash when i up the limit to 250.
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

The thread limit? I'm not surprised, I put it at 50 for a reason :) That's just the number of concurrent requests, it's not the number of machines it'll query in total. It's quite easy to ruin a system by running too many things at once.

I imagine it'll recover, even if it's running 250 simultaneous threads, no fun until it does though.
Avatar of Lennart Giaccotto

ASKER

Ah, that explains a lot :-). Now for the last question. This script seems to only display the username who has executed it. how can i let it search for either all users that are logged in or just a specific one?
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

The should show the name of the user logged into the PC using the interactive session. If you want users across all sessions things become a little more complex (that's when you need what quser is doing). Is that what you're looking for?
Avatar of Lennart Giaccotto

ASKER

I need to see all users accross the complete domain that are currently logged on. also when the session is disconnected
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Okay, no problem. One sec.
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Lennart Giaccotto

ASKER

Yes! This works beautiful! It gives me a complete list of users logged in anywhere in the domain! Thank you!
Avatar of Lennart Giaccotto

ASKER

This Script does exactly what i ask. it shows me every user that is logged in somwhere within the domain
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo