Untitled

 avatar
unknown
plain_text
a year ago
643 B
28
Indexable
# Replace "abcd" with the actual username
$username = "abcd"

# Get all active remote desktop sessions
$sessions = Get-RemoteDesktopSession

# Filter sessions for the specified user
$userSessions = $sessions | Where-Object { $_.UserName -eq $username }

# Check if any sessions are found for the user
if ($userSessions) {
  # User is logged in to at least one computer
  Write-Host "User $username is currently logged in to the following computers:"
  $userSessions | ForEach-Object { Write-Host $_.ComputerName }
} else {
  # User is not logged in to any computers
  Write-Host "User $username is not currently logged in to any computers."
}