<# .SYNOPSIS This script will look for the SharePoint correlation ID in a given time span and display its information to the screen. .DESCRIPTION I could never remember the syntax so a script was in order, pop it on the web and I can get to it all the time. Used for SharePoint 2010 & SharePoint 2013. ---------------------------------------------------------------------------------------------------------------------- History Version number | Data | Comment 1.00 | 22 October 2014 | Initial script. ---------------------------------------------------------------------------------------------------------------------- .LINK http://www.glossover.co.uk/archives/333 .EXAMPLE 4 examples GetSPError -GUIDToFind 00000000-0000-0000-0000-000000000000 -NumberOfMinutes 10 This will only look in the last 10 minutes of the log. ---- GetSPError -GUIDToFind 00000000-0000-0000-0000-000000000000 -NumberOfMinutes 0 This will look at all of the the log. ---- GetSPError -GUIDToFind 00000000-0000-0000-0000-000000000000 -NumberOfMinutes 10 -FileName error.txt This will only look in the last 10 minutes of the log and send the output to the error.txt file. ---- GetSPError -GUIDToFind 00000000-0000-0000-0000-000000000000 -NumberOfMinutes 0 -FileName error.txt This will look at all of the the log and send the output to the error.txt file. #> Param ( [Parameter(Mandatory=$true, HelpMessage="Please enter the SharePopint correlation ID")] [alias("GUIDToFind")] [ValidateNotNull()] #The SharePoint SharePopint correlation ID you are looking for. [string]$GUID, [Parameter(Mandatory=$true, HelpMessage="Enter how far back in the log you would like to search, if you are unsure then enter 0 and the entire log will be searched.")] [alias("NumberOfMinutes")] [ValidateNotNull()] #To save searching the entire log you can search only within the last few minutes. #If you want to search the entire log the pass over the number "0" (this is the default). [int]$Minutes, [Parameter(Mandatory=$false, HelpMessage="Send to output to this file name.")] [alias("FileName")] [ValidateNotNull()] #Save the results to a file name. [string]$SaveToFileName ) $startTime = Get-Date if ( $SaveToFileName -eq "" ) { #Just send all output to the screen. Write-Host "Start time : $startTime" write-host "Looking for the Correlation ID ($GUID) with this following command." if ( $Minutes -eq 0 ) { write-host "Get-SPLogEvent | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize" Write-Host "--Error information if found - Start ------------------------" Get-SPLogEvent | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize } else { write-host "Get-SPLogEvent -StartTime (Get-Date).AddMinutes(-$Minutes) | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize" Write-Host "--Error information if found - Start ------------------------" Get-SPLogEvent -StartTime (Get-Date).AddMinutes(-$Minutes) | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize } Write-Host "--Error information if found - End --------------------------" $endTime = Get-Date Write-Host "Script execution time : $( New-TimeSpan $startTime $endTime)." Write-Host "End time : $endTime" } else { #Send all output to the file. "Start time : $startTime" > $SaveToFileName "Looking for the Correlation ID ($GUID) with this following command." >> $SaveToFileName if ( $Minutes -eq 0 ) { "Get-SPLogEvent | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize >> $SaveToFileName" >> $SaveToFileName "--Error information if found - Start ------------------------" >> $SaveToFileName Get-SPLogEvent | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize >> $SaveToFileName } else { "Get-SPLogEvent -StartTime (Get-Date).AddMinutes(-$Minutes) | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize >> $SaveToFileName" >> $SaveToFileName "--Error information if found - Start ------------------------" >> $SaveToFileName Get-SPLogEvent -StartTime (Get-Date).AddMinutes(-$Minutes) | Where{$_.Correlation -eq $GUID} | Format-Table Category, Message -wrap -AutoSize >> $SaveToFileName } $endTime = Get-Date "--Error information if found - End --------------------------" >> $SaveToFileName "Script execution time : $( New-TimeSpan $startTime $endTime)." >> $SaveToFileName "End time : $endTime" >> $SaveToFileName }