Skip to content

Instantly share code, notes, and snippets.

@sowamazing
Created January 21, 2016 16:34
$Process = New-Object system.Diagnostics.Process
$Process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo("C:\JennsFolder\projects\Loggly\tailclient-1.0.1\bin\livetail.bat","-m `"HTTP`"")
$Process.StartInfo.RedirectStandardOutput = $true
$Process.StartInfo.RedirectStandardError = $true
$Process.StartInfo.UseShellExecute = $false
$Process.Start() | Out-Null
$fromdate = Get-Date
$todate = ""
#excel info
$excel_file_path = 'C:\JennsFolder\projects\Loggly\tailclient-1.0.1\ErrorGraph.xlsx'
$Excel = New-Object -ComObject Excel.Application
$ExcelWorkBook = $Excel.Workbooks.Open($excel_file_path)
$ExcelWorkSheet = $Excel.WorkSheets.item("sheet1")
$ExcelWorkSheet.activate()
try {
while (!$Process.HasExited){
#Write-Host $Process.StandardOutput.ReadLine()
$splitString = $Process.StandardOutput.ReadLine() -split "/1.1`" "
if ($splitString[1])
{
Write-Host $splitString[1].Substring(0, 3)
$datarow = 5
if ($splitString[1].Substring(0, 3) -eq "500")
{
$data = $ExcelWorkSheet.Cells.Item($datarow,1).Value2 #500 errors
if ($data)
{
$data = [int]$data + 1
}
else
{
$data = 1
}
$ExcelWorkSheet.Cells.Item($datarow,1) = $data
Write-Host $data
}
if ($splitString[1].Substring(0, 3) -eq "200")
{
$data = $ExcelWorkSheet.Cells.Item($datarow,2).Value2 #200 errors
if ($data)
{
$data = [int]$data + 1
}
else
{
$data = 1
}
$ExcelWorkSheet.Cells.Item($datarow,2) = $data
Write-Host $data
}
}
}
}
finally
{
Write-Host "Cleaning up....."
$todate = Get-Date
$ExcelWorkSheet.Cells.Item(1,1) = $("From " + $fromdate.ToString() + " to " + $todate.ToString())
$ExcelWorkBook.Save()
$ExcelWorkBook.Close()
$Excel.Quit()
Write-Host "Closed excel"
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Stop-Process -Name EXCEL -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment