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:
1 2 3 4 5 |
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)}} |
That’s not huge, that’s a puppy. But nevertheless, that verbose format will help the unenlightened read and understand it.
Nice. Need to purge an app cache in a regular basis and this is perfect for narrowing it to the regular user. Thanks!
BTW – Michel de Rooij is clearly a douche.
Hi Mars,
Happy I could help.
Please, don’t call people names. If they want to express their opinion then let them.
If they really are acting like a douche, there is always a little thing called karma.
Like Sun Tsu wrote: If you wait by the river long enough, the bodies of your enemies will float by…
Jeff.
Jeff, you too are a douche for the last comment.
Yes, I am.
I want to count the number of times user logged in to a desktop machine using his/her domain credentials, anyway to do this using same powershell script ?
when i use few powershell scripts its fetching the total login count from AD server , but i want to count number of times each domain user logged into Desktop machine say MACHINE1 and two users Mark and Tom
Wow this is just what I was looking for!
I spent the past couple of days figuring out how to get the last logged on user. I got it working by querying the System event log (Get-WinEvent) and it worked for my purpose but this helped me get the correct result every time – thank you!