Last active
August 29, 2015 14:00
-
-
Save bill-long/11067169 to your computer and use it in GitHub Desktop.
Point this to a Directory Service log in CSV format, and it counts each unique 1216 event and tells you how many times that particular type of 1216 event occurred.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param($file) | |
$reader = new-object System.IO.StreamReader($file) | |
$errorsDictionary = new-object 'System.Collections.Generic.Dictionary[string,int]' | |
$nextLineIsError = $false | |
while ($null -ne ($buffer = $reader.ReadLine())) | |
{ | |
if ($nextLineIsError) | |
{ | |
$nextLineIsError = $false | |
if ($errorsDictionary.ContainsKey($buffer)) | |
{ | |
$errorsDictionary[$buffer]++ | |
} | |
else | |
{ | |
$errorsDictionary.Add($buffer, 1) | |
} | |
} | |
elseif ($buffer.StartsWith("Error value:")) | |
{ | |
$nextLineIsError = $true | |
} | |
} | |
$reader.Close() | |
$errorObjects = @() | |
foreach ($key in $errorsDictionary.Keys) | |
{ | |
$obj = New-Object PSObject | |
Add-Member -InputObject $obj -MemberType NoteProperty -Name Count -Value $errorsDictionary[$key] | |
Add-Member -InputObject $obj -MemberType NoteProperty -Name ErrorText -Value $key | |
$errorObjects += $obj | |
} | |
$errorObjects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment