How to query the SharePoint ULS logs with Powershell


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:

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:

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:



No ratings yet.

Please rate this

How to query the SharePoint ULS logs with Powershell

| SharePoint | 2 Comments
Profile photo of Kushhh
About The Author


  • Profile photo of Bob Mixon
    Bob Mixon
    Reply Report user

    I use PowerShell for most debugging in SharePoint.  Opening ULS log files and filtering/traversing large logs is almost unusable.  Using the PowerShell approach allows you to focus on specific correlation ID’s, etc.

    Another PowerShell cmdlet you may be interested in is Merge-SPLogFile.  This command allows you to merge log files across servers.  More information can be found here:

    I have a diagnostic library (PowerShell) I include in most all of my scripts.  My Merge log files function is:

    function Merge-SPLogFileByCorrelationID

        $ls = “”.PadRight($LeadingSpaceCount,” “)

        $diagConfig = Get-SPDiagnosticConfig
        $ulsLogLocation = $diagConfig.LogLocation + “\MergeLog-Correlation (” + $CorrelationID + “).log”

        Write-Verbose [string]::Format(“$ls- Writing merged logs to file [{0}].”, $ulsLogLocation))

            Merge-SPLogFile -Path $ulsLogLocation -Correlation $CorrelationID -Overwrite
            Merge-SPLogFile -Path $ulsLogLocation -Correlation $CorrelationID

    Which will merge log files, across the farm, by correlation ID!

    Thank you for the post.  A “master” developer has many debugging techniques in his/her toolbox…

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">