-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloggedinusers
More file actions
27 lines (23 loc) · 886 Bytes
/
loggedinusers
File metadata and controls
27 lines (23 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Import the ActiveDirectory module
Import-Module -Name 'ActiveDirectory'
# Get the domain name
$domain = Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Domain
# Get the list of computers in the domain
$computers = Get-ADComputer -Filter * -SearchBase "DC=$($domain),DC=local" | Select-Object -ExpandProperty Name
# Iterate through each computer
$computers | ForEach-Object {
# Get the logged in users on the computer
$users = quser /server:$_
# Check if any users are logged in
if ($users -eq $null) {
Write-Output "There are no logged in users on the computer '$_'."
} else {
# Print the details of each logged in user
$users | ForEach-Object {
Write-Output "Computer: $_"
Write-Output "User: $($_.USERNAME)"
Write-Output "Session: $($_.SESSIONNAME)"
Write-Output "Idle Time: $($_.IDLE TIME)"
}
}
}