Quantcast
Channel: Microsoft – JeffOps
Viewing all articles
Browse latest Browse all 120

PowerShell – Find the name and time of the last logged on user

$
0
0

This one goes on the category of crazy-oneliners.
After I finished writing it I looked back and saw just how crazy huge it was…
Nevertheless, I still like to share:

Get-WmiObject -Class Win32_NetworkLoginProfile | 
Sort-Object -Property LastLogon -Descending | 
Select-Object -Property * -First 1 | 
Where-Object {$_.LastLogon -match "(\d{14})"} | 
Foreach-Object { New-Object PSObject -Property @{ Name=$_.Name;LastLogon=[datetime]::ParseExact($matches[0], "yyyyMMddHHmmss", $null)}}

Post to Twitter


Viewing all articles
Browse latest Browse all 120

Trending Articles