Created
June 7, 2014 07:26
-
-
Save ghotz/af65a1d178d8119e325e to your computer and use it in GitHub Desktop.
Split and strip SQL Server ERRORLOG file
This file contains hidden or 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
# just a draft, need massive polishing :) | |
cls; | |
$reader = new-object System.IO.StreamReader("ERRORLOG") | |
$count = 1 | |
$numlines = 0 | |
$fileName = "{0}{1}.{2}" -f ("ERRORLOG_stripped_", $count, "txt") | |
while(($line = $reader.ReadLine()) -ne $null) | |
{ | |
if ((++$numlines % 1000) -eq 0) { Write-Output "Processed $numlines lines" } | |
if (!($line -match "Login succeeded*" -or $line -match "Login failed*" -or $line -match "Error: 18456*")) | |
#if (!($line -match "I/O is frozen*" -or $line -match "I/O was resumed*" -or $line -match "Database backed up.*")) | |
{ | |
Add-Content -path $fileName -value $line | |
} | |
if((Get-ChildItem -path $fileName).Length -ge 10MB) | |
{ | |
++$count | |
$fileName = "{0}{1}.{2}" -f ("ERRORLOG_stripped_", $count, "txt") | |
} | |
} | |
$reader.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment