Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Pulling security log data

Reply
 
Old 07-15-2008   #1 (permalink)
Karl Greenley


 
 

Pulling security log data

I'm trying to put together a script that will poll a set of domain computers and pull login and unlock data from the security logs. After a a good deal of searching, I've got the basic syntax worked out, but what I managed to put together seems to take forever (if it's actually progressing at all) to pull or filter the data from one machine.

Below is what I've cobbled together to gather the data from one machine, but it's about time to consult a more authoritative source than Google for piecing this together.

Thanks to any who can offer advice on how to do this right:
---

$strComputer = "."

#Establish date search range. One day for initial testing, will eventually revise it to
#go back to the last search on a machine by machine basis
$d=Get-Date
$startday=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime($d.AddDays(-1))
$today=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime($d)


#Pull the security log
#$colItems = get-wmiobject -class Win32_NTLogEvent -namespace "root\cimv2" -computername $strComputer `
# –query "select EventCode,TimeWritten,User,Message from Security and (EventCode = 528 or EventCode = 538) `
# and TimeWritten >= $yesterday and TimeWritten < $today and (Message LIKE $Unlock or Message LIKE $Login) " `
# | sort "TimeWritten"


$co = new-object Management.ConnectionOptions
$co.enableprivileges = $true
$ms = new-object Management.ManagementScope("\\$strComputer\root\cimv2", $co)
$ms.connect()
$q = new-object Management.ObjectQuery("select TimeWritten,EventCode,Message,User from win32_ntlogevent where logfile='Security' ")
$mos = new-object Management.ManagementObjectSearcher($ms, $q)
$secLog = $mos.get()
$secLogRecent = $secLog | where-object {$_.TimeWritten -ge $startday -and $_.TimeWritten -lt $today}
$colItems = $secLogRecent | where-object { $_.message -like "*Logon Type:'t2*" -or $_.message -like "*Logon Type:'t7*" } | sort "TimeWritten"


My System SpecsSystem Spec
Old 07-16-2008   #2 (permalink)
bass_player


 
 

Re: Pulling security log data

Why not use LogParser for this? It's a lot easy

http://www.microsoft.com/downloads/d...displaylang=en

"Karl Greenley" wrote in message news:2008715153330kgreenley@xxxxxx
Quote:

> I'm trying to put together a script that will poll a set of domain
> computers and pull login and unlock data from the security logs. After a a
> good deal of searching, I've got the basic syntax worked out, but what I
> managed to put together seems to take forever (if it's actually
> progressing at all) to pull or filter the data from one machine.
>
> Below is what I've cobbled together to gather the data from one machine,
> but it's about time to consult a more authoritative source than Google for
> piecing this together.
>
> Thanks to any who can offer advice on how to do this right:
> ---
>
> $strComputer = "."
>
> #Establish date search range. One day for initial testing, will eventually
> revise it to
> #go back to the last search on a machine by machine basis
> $d=Get-Date
> $startday=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime($d.AddDays(-1))
> $today=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime($d)
>
>
> #Pull the security log
> #$colItems = get-wmiobject -class Win32_NTLogEvent -namespace
> "root\cimv2" -computername $strComputer `
> # -query "select EventCode,TimeWritten,User,Message from Security and
> (EventCode = 528 or EventCode = 538) `
> # and TimeWritten >= $yesterday and TimeWritten < $today and (Message
> LIKE $Unlock or Message LIKE $Login) " `
> # | sort "TimeWritten"
>
>
> $co = new-object Management.ConnectionOptions
> $co.enableprivileges = $true
> $ms = new-object Management.ManagementScope("\\$strComputer\root\cimv2",
> $co)
> $ms.connect()
> $q = new-object Management.ObjectQuery("select
> TimeWritten,EventCode,Message,User from win32_ntlogevent where
> logfile='Security' ")
> $mos = new-object Management.ManagementObjectSearcher($ms, $q)
> $secLog = $mos.get()
> $secLogRecent = $secLog | where-object {$_.TimeWritten -ge $startday -and
> $_.TimeWritten -lt $today}
> $colItems = $secLogRecent | where-object { $_.message -like "*Logon
> Type:'t2*" -or $_.message -like "*Logon Type:'t7*" } | sort "TimeWritten"
>
My System SpecsSystem Spec
Reply

« AD | count »
Thread Tools


Similar Threads
Thread Forum
Application Data Security in ProgramData folder Vista security
Pulling in scripts from the web PowerShell
Something that has me pulling my hair out! Vista security
Data Security on DVR's and CD's Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46