Cruisader03 nailed it already, but I'd offer a slightly more streamlined approach using the datetime parse method, and V2 new-object Property parameter.
$name = '.'
Get-WmiObject Win32_NetworkLoginProfile -ComputerName $name|
#Filter out any non valid DTG
Where-Object {$_.LastLogon -match "(?<dtg>\d{14}\.\d{6}\S)(?<offset>\d+)$"}|
#Foreach valid entry find the last logon dtg
ForEach-Object {
# Win32_NetworkLoginProfile formats the utc offset in seconds this
# Breaks the DateTime parser. We reformat the string converting
# the offset back to hours
$CorrectedDTG = "{0}{1:00}" -f $matches.dtg, ($matches.offset/60)
New-Object PSObject -Property @{
Name=$_.Name
LogonTime=[datetime]::ParseExact($CorrectedDTG, "yyyyMMddhhmmss.ffffffzz", $null)
}
} |
Sort-Object -Descending LogonTime |
Select-Object -First 1
~Glenn