Some thoughts on programming stuff

Troubleshooting errors using PowerShell in SharePoint

Today I would like to share with you an useful script to help on troubleshooting errors using PowerShell in SharePoint when some unexpected exception happens . This script can help you on tracing the exact cause of a bug in the application while relieving you from opening the entire log file and search for the error message in a not so productive way.

The SharePoint logs folder - Troubleshooting errors using Powershell in SharePoint
The SharePoint logs folder (Microsoft docs)

These logs are written by SharePoint and according to Microsoft, this is what you get from it:

“The Unified Logging Service (ULS) is the service that is responsible for keeping an eye on SharePoint and reporting what it finds. It can report events to three different locations:

  • SharePoint trace logs
  • Windows Event Log
  • SharePoint logging database

Where the event is logged (and if it’s logged at all) depends on the type of event, as well as how SharePoint is configured. The ULS is a passive service, which means that it only watches SharePoint and reports on it; it never acts on what it sees.”

The prerequisites for troubleshooting errors in SharePoint

You will need two things:

  • The correlation Id of the problem;
  • You need to have access to SharePoint Management Shell or PowerShell as Admin in the SharePoint server.

The PowerShell to grab the logs

Once you got those two things, just paste the code below replacing the CorrelationId parameter with your own Id.

This example is extremely simple, but saved my life a thousand times. The Get-SPLogEvent accepts other parameters too like Start and End Time too, that will help you on filtering better. Here is how the Log will be formatted in the text file.

That’s it! I hope this blog post can help you giving some PowerShell ideas to let you develop your own script and be more productive when investigating and troubleshooting errors using PowerShell in SharePoint. Also you can check my other posts related to Powershell here.

References:
Zimmergren
Technet

1 Comment

  1. PLA

    Here’s one useful command that can be always used:
    Get-SPLogEvent | Out-GridView

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑