contar_sesiones_de_usuario_activas
You can include the conditions for LogonType 2 and 10 to filter the sessions before counting the unique start times. Here's the modified script:
# Query WMI for active user sessions $activeSessions = Get-WmiObject Win32_LogonSession -ComputerName . # Create a hashtable to store unique start times $uniqueStartTimes = @{} # Iterate through each session foreach ($session in $activeSessions) { # Check if the session is interactive (LogonType 2) or remote (LogonType 10) if ($session.LogonType -eq 2 -or $session.LogonType -eq 10) { # Get the start time of the session $startTime = $session.StartTime # Add the start time to the hashtable if it doesn't already exist if (-not $uniqueStartTimes.ContainsKey($startTime)) { $uniqueStartTimes[$startTime] = $true } } } # Count the number of unique start times $uniqueSessionsCount = $uniqueStartTimes.Count # Output the number of unique sessions Write-Output "Number of unique interactive or remote sessions: $uniqueSessionsCount"
This script now includes a condition to check if the LogonType is either 2 (interactive) or 10 (remote). Only sessions that match these LogonTypes will have their start times added to the hashtable for counting.
contar_sesiones_de_usuario_activas.txt · Last modified: 2024/10/17 21:42 by 127.0.0.1
