Skip to content
Jan Ryen

Jan Ryen

Learn from every failure and every success. Cultivate a Positive Mental Attitude.

Jan Ryen

  • About
  • Blog
  • Readinglist
  • Twitter Feed

Get last logged on user with PowerShell

Share via:

  • Facebook
  • Twitter
  • LinkedIn
  • Email
  • Copy Link
  • More

 

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
# Get last logged on user on local computer
$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"}}}
$TimeProperty = @{n="Time";e={$_.TimeGenerated}}
Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProperty | select -First 1
 
# Get last 100 logged on user entries on local computer
$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"}}}
$TimeProperty = @{n="Time";e={$_.TimeGenerated}}
Get-EventLog System -Source Microsoft-Windows-Winlogon | select $UserProperty,$TypeProperty,$TimeProperty | select -First 100
 
 

 

Share via:

  • Facebook
  • Twitter
  • LinkedIn
  • Email
  • Copy Link
  • More
  • ← Find SMTP addresses using ActiveDirectory module in PowerShell
  • Fun tip about powershell. You can pipe to the clipboard →

Please Follow:

  • LinkedIn
  • Parler
  • Twitter
  • Reddit

Recent Posts

  • [Solved] NIC error modern UI – Windows cannot access …
  • Automate set up of first Active Directory DC with powershell
  • What to memorize
  • Get Network card driver version remotely
  • Share folder with PowerShell

Categories

  • Business
  • DevOps
  • Hyper-V
  • KnowledgeBase
  • Linux
  • Powershell
  • Productivity
  • Windows Server
  • Windows Server 2012 R2
  • Terms of Service and Privacy Policy
  • Cookie Policy
© 2025 Jan Ryen | Designed by: Theme Freesia | Powered by: WordPress
  • Facebook
  • Twitter
  • LinkedIn
  • Email
  • Copy Link
  • More Networks
Share via
Facebook
X (Twitter)
LinkedIn
Mix
Email
Print
Copy Link
Powered by Social Snap
Copy link
CopyCopied
Powered by Social Snap