PS Script Pull Event Log data

Below is a script I wrote to help identify computers that had a trust relationship issue with the Active Directory domain.  This script searches for an event on the domain controller that you run this on(please use caution).  It looks for an event that has an event ID of 5723, and that happened today.  Then it pulls the name of the computer identified in the event.  This script allows me to know and address the computers with issues before I get a support call.

#Get todays date;
$today = get-date -uformat "%m/%d/%Y"; 
#Create array for computers;
$cName = @();
#Pull events from system event log that are errors;
$events = Get-EventLog -log system -entrytype Error 
#Filter the events where eventID is 5723 and the time written is today;
$events = $events | where { 
 $_.eventID -eq 5723 -and $_.timewritten -like "$today*" 
}
#Select computer name property;
$events = $events | select ReplacementStrings;
#Add computer names to array;
$events | foreach { $cName += $_.replacementstrings[0];}; 
#Print array leaving out duplicates
$cName | select -uniq;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: