Thursday, February 14, 2013

Last User Login to Current Computer

Last User Login to Current Computer. Love this. Give me a list of domain users and their last login time to the current computer.

$data = @()
$NetLogs = Get-WmiObject Win32_NetworkLoginProfile
foreach ($NetLog in $NetLogs) {
if ($NetLog.LastLogon -match "(\d{14})") {
$row = "" | Select Name,LogonTime
$row.Name = $NetLog.Name
$row.LogonTime=[datetime]::ParseExact($matches[0], "yyyyMMddHHmmss", $null)
$data += $row
}
}

$data

No comments:

Post a Comment