Powershell Script – Get the Most Recent User Login / Logoff Events
- Posted by
- Posted on January 6, 2021
- Computers, Servers
- No Comments.

This great little Powershell script will generate a .csv file, that you can open in excel, which will list each time a user logged in and logged out from the computer or server you run it on.
I believe the only downside is that the list only goes as far back as the logs do on the computer or server you run it on.
Powershell Script
$UserProperty = @{n=”user”;e={(New-Object System.Security.Principal.SecurityIdentifier $_.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])}}
$TypeProperty = @{n=”Action”;e={if($_.EventID -eq 7001) {“Logon”} else {“Logoff”}}}
$TimeProeprty = @{n=”Time”;e={$_.TimeGenerated}}
Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProeprty | export-csv -path C:\logs.csv -NoTypeInformation
Recent Posts
- Why Tinning Stranded Wires Can Cause Problematic Connections
- Preparing Your IP Network for Voice and Video Traffic: Bandwidth, QoS, Wi-Fi, and Network Performance
- Allow Local Network Access in Google Chrome and Microsoft Edge Using Group Policy
- Understanding Cisco IOS Software: Versions, Features, Image Names, and Compatibility
- Troubleshooting Word Automatically Changing Fonts
Archives
- November 2026
- October 2026
- September 2026
- May 2026
- February 2026
- January 2026
- December 2025
- October 2025
- September 2025
- August 2025
- July 2025
- June 2025
- February 2025
- January 2025
- July 2022
- February 2022
- January 2021
- July 2020
- May 2020
- February 2020
- December 2019
- August 2019
- January 2019
- July 2018
Categories
- Audio / Video
- Business
- Cisco
- Computers
- Hacking
- IT Support
- Lab
- Linux
- Mac OS
- Management
- Microsoft Applications
- Networking
- Poly
- Printer
- Router
- Security
- Servers
- Switch
- Uncategorised
- Video Conferencing
- Virtualization
- Website
- Windows
