SharePoint 2013 Diagnostics Powershell trick

Posted on 12/29/2013 @ 5:14 AM in #SharePoint by | Feedback | 2253 views

If you work with SharePoint, you have for sure dealt with a few correlation ids. Its this random guid that shows up, hiding the actual error from you. #WTF

Well, you can go into your logs directory and find out what the actual error is. How do we do that? Well .. you go to the logs directory .. you open the file in notepad or ulsviewer etc. .. HAHA! NO!

Here is what you do, you run the below command,

   1:  Get-Content *.log | select-string $correlationId

LOL Yep! That little command will spew out all the ULS entries specific to your correlation ID you care about. You can redirect all that output to a file using

   1:  Get-Content *.log | select-string $correlationId > outfile.txt

Or if you prefer, just stick it in the clipboard using

   1:  Get-Content *.log | select-string $correlationId | clip

Of special interest is the new diagnostic capability available in SharePoint 2013. Frequently ULS log entries are too many to sift through. Creating a new diagnostics session allows us to group all our actions into a single correlation id, using which we can filter data relevant to us. Here is how you can use this facility.

   1:  $correlationId = [guid]::NewGuid()
   2:  Start-SPDiagnosticsSession -CorrelationId $correlationId -Dashboard:$true -TraceLevel Verbose
   3:  -- run your other powershell commands here
   4:  Stop-SPDiagnosticsSession
   5:  Get-Content *.log | select-string $correlationId | clip

Nice huh? I thought so.

Sound off but keep it civil:

Older comments..