Solved

Powershell script to for events for a user

Posted on 2015-01-29
10
83 Views
Last Modified: 2015-01-29
To keep it simple i put a users SID in the UserID field.  I can search by event ID's ETC but not user ID.  What am i doing wrong?

Server 2008 and 2012 domain.

Thanks


$objUser = New-Object System.Security.Principal.NTAccount("$Domain", "$user")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value

$DCs = "DC1", 	"DC2", 	"DC3", 	


ForEach($DC in $DCs){


Get-WinEvent -FilterHashTable @{LogName="Security" ;StartTime = (Get-Date).AddDays(-1); UserID="S-1-5-21-1229272821-1220945662-725345543-1508268"   }  -ComputerName $DC | Select Message, TimeCreated |ft -AutoSize


}

Open in new window

0
Comment
Question by:SLPowers
  • 4
  • 3
  • 3
10 Comments
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
The only explanation is that that SID is invalid, or the event info does not contain any or this SID. My Security Log does not contain any SIDs; Application Log does.
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
I think you're expecting events to have a matching UserID which actually don't.  Often the message contains a field for identity, but this is not the same as the UserID property.  In the Security log, I let a query run for a few minutes and no events with UserId were returned, however, I did find some in the Application log.
0
 

Author Comment

by:SLPowers
Comment Utility
Thanks

How can i use Get-WinEvent and filter the hash table for user id.  Piping to a "Where" statements takes hours so i cant do that.

Thanks
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
You mean a user ID contained in the message?
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Probably the best way to handle this is to set up a task with a trigger on the event IDs to monitor on each server, or just running periodically scanning a small time period's events. Actions can be to send mail or similar.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:SLPowers
Comment Utility
Is there no way to scan a log for a user ID?

This is horrible.
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
You could modify yours to something like the following.  It will match the SID anywhere in the message property.
$objUser = New-Object System.Security.Principal.NTAccount("$Domain", "$user")
$strSID = ($objUser.Translate([System.Security.Principal.SecurityIdentifier])).Value

$DCs = "DC1", 	"DC2", 	"DC3", 	
ForEach($DC in $DCs){
Get-WinEvent -FilterHashTable @{LogName="Security" ;StartTime = (Get-Date).AddDays(-1); Data=$strSID   }  -ComputerName $DC | Select Message, TimeCreated |ft -AutoSize
}

Open in new window


But really, the question becomes, what are you trying to do?
0
 

Author Comment

by:SLPowers
Comment Utility
Search through our DC's for a given user for log on and log off attempts.
0
 

Author Closing Comment

by:SLPowers
Comment Utility
That worked!!

Thanks!
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
You're probably going to want to include the IDs in the fitler hashtable then, or you'll likely get extraneous events.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Set OWA language and time zone in Exchange for individuals, all users or per database.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now