Wednesday, December 17, 2014

Parsing Log File with PowerShell

Interesting article

http://matthewyarlett.blogspot.co.uk/2014/11/quick-and-dirty-parsing-logs-with.html

here is the code for reference

# Set the path to the log files            
$path = "C:\Temp\Logs"
# Get a collection of all the log files (anything ending in .log)
$files = Get-ChildItem -Path $path -Filter "*.log"
# Pipe the collection of log files to the ForEach-Object cmdlet
# (the alias of ForEach-Object is %)
$files | %{
# Call the OpenText method, to return a System.IO.StreamReader object
$file = $_.OpenText();
# Record the current line number (to use in the console output)
$lineNum = 1;
Write-Host "Checking file"$_.Name -f Yellow;
# Use the EndOfStream method (which returns true when you have reach the end
# of the file), read each line of the file.
while($file.EndOfStream -ne $true)
{
# Read the next line in the file
$line = $file.ReadLine();
if($line -ne $null)
{
# Use the String ToLower and Contains methods to check for occurances
# of the strings (or values) you need to check the file for
# In this example, I'm looking for any instances of the text "error" or "exception"
if($line.ToLower().Contains("error") -or $line.ToLower().Contains("exception"))
{
# If the current lines contains a match, write the line number
# and line text out to the console
Write-Host "Line: $lineNum " -NoNewline -ForegroundColor Green;
Write-Host $line -f Red;
}
}
# Increment the line number
$lineNum++;
}
}

Wednesday, July 2, 2014

ISE–PowerShell Integrated Scripting Environment

Here is some fun with the Windows PowerShell Integrated Scripting Environment or ISE

Start ISE

simply type ise

Start ISE as administrator

start-process PowerShell_ISE –verb RunAs

Customize ISE for SharePoint

http://thecloudengineer.blogspot.com/2011/10/create-ise-enabled-for-sharepoint.html

Configuring the PowerShell ISE for use with Git and GitHub


http://mikefrobbins.com/2016/02/09/configuring-the-powershell-ise-for-use-with-git-and-github/