by Kushhh

2015-10-15

Did you know that the SharePoint ULS logs can be queried, filtered and output to a text file or GridView (allowing for  additional filtering).

This can be really handy to help troubleshoot problems, so this post offers 3 examples.

How to export ULS logs to a GridView for further filtering

Execution of the Powershell Script (below) will open a GridView showign the matching results. The GridView also has additional filtering capabilities allowing you to really target in on what you’re looking for.

Powershell script:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{     
   Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
}

Get -SPLogEvent -StartTime "10/15/2015 11:19" -EndTime "10/15/2015 11:20" | out GridView

Screenshot of the ULS Logs in a Powershell GridView:

How to export the ULS Logs to a text file

In the example blow, you will see how to query and output the ULS Logs to a text file.

Powershell script:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{     
   Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
}

Get -SPLogEvent -StartTime "10/15/2015 11:19" -EndTime "10/15/2015 11:20"  >> C:\ULSlogs.txt

How to search the ULS Logsfor a designated string

In this example, we show how you can search for text withing the Logs.

Powershell script:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{     
     Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
}

Get-splogevent | ?{$_.Correlation -eq "<Correlation ID>"} | select Area, Category, Level, EventID,Message | Format-List > C:\ULSlogs.txt

 

About the author 

Kushhh