Hello,
I've been working on a lot of scripts lately and I'm having some trouble parsing the data I'm getting. I have a quite a few machines that are online but with no one logged into them. I am about to get the information quickly but I'm having a hard time parsing the data properly. I created a function to write to a log file so we can easily read it. This is how I'm getting the data.
$data = @()
$NetLogs = Get-WmiObject Win32_NetworkLoginProfile -computername $PC 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 | Sort LogonTime -Descending | select-object -first 1
and this is what it outputs:
Name LogonTime ---- --------- AD\ServiceAccount 8/9/2013 10:17:10 AM
I then wrote a simple function to write a log file so I want it write the log like:
Logwrite "name,logontime"
I've tried a ton of different combinations and I've had no success. What is the best way to go about this?