Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/11067169 to your computer and use it in GitHub Desktop.
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.
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