Find the name & time of the last logged on user using powershell
Jeff Wouter Powershell MVP has written the below script which find the name and time of the last logged on user.
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)}}
Output:
LastLogon Name
--------- ----
3/13/2014 10:44:19 PM HYPERV\Administrator
0 comments :