Powershell 


You will use powershell in a day to day work especially if you are an administrator to take backup of lists, sites, site collections and whenever you get an error with the correlation ID on the SharePoint site etc.

In this post we will talk about how to find the error details based on correlation id using powershell in SharePoint.

You will not only learn how to write the scripts which is required to solve the problems and  also the way to learn the basics so that you can write scripts on your own.

You can find the basics that has been used in this article by highlighted as Get the Basics.



 Find the error details based on correlation Id:

In SharePoint you commonly see correlation id whenever you get the error on the SharePoint site.

To get more details on the error based correlation  Id  use  get-splogevent  command. 


See the below script to find the exact error information based on correlation Id. 

Get-splogevent will get the ULS  logs details from that particular server (WFE or Application) where you will run the below command.


#Example of using get-splogevent

get-splogevent -starttime (get-date).addminutes(-20) | where-object { $_.correlation -eq "e434f79b-68bb-40d2-0000-03a47eae1bf9" } | fl message > c:\errors1.txt


Before elaborating the above script  use the below commands to get more about get-splogevent.


Get the Basics:

You will learn about any command once you get the basic usage of that particular command.

To starts hands on .......

Launch your SharePoint 2013 management shell from all programs under Microsoft SharePoint 2013 products.

Use get-help command. This command will display the all the required help regarding the get-splogevent,  so that you can learn more about it.


#Example of using get-help command

get-help get-splogevent

Examples:

Use examples parameter along with get-help command to get few samples on how to use the command.

#Example of using examples parameter and writing the details to a text file

get-help get-splogevent -examples >c:\examples.txt

To get detailed information about get-splogevent.

#Example of using details parameter and writing the details to a text file

get-help get-splogevent -detail >c:\details.txt

For complete information about get-splogevent.

#Example of using full parameter and writing the details to a text file

get-help get-splogevent -full >c:\full.txt

Compare the results return by above three commands, so that in the future whenever you want help you can use the suitable command based on your choice.

By running the above commands you are writing the output to  a text file so that it can easily readable.

By now you know how to use get-help command. Its easy ha how to know about the commands.

Let's move on, now we will explore about the example we have written on top on how to get error details using get-SPlogevent.


get-splogevent -starttime (get-date).addminutes(-20) | where-object { $_.correlation -eq "e434f79b-68bb-40d2-0000-03a47eae1bf9" } | fl message > c:\errors1.txt


In the above script the highlighted portion indicates that we are trying to get the logs before 20 minutes with the current date. You can change according to your requirement.

Pipeline (|)

After that addmintutes you can see the pipe (|) symbol  from above script which is basically used to  pass the collection of values from one powershell command to the other.

Here it is passing the values that have been executed by get-splogevent to where-object.

Check here for detailed information on pipeline.

Where-Object:

As name suggests "Where-object" command use to filter the values based on the results of other commands that has run before this where-object command.


get-splogevent -starttime (get-date).addminutes(-20) | where-object { $_.correlation -eq "e434f79b-68bb-40d2-0000-03a47eae1bf9" }    | fl message > c:\errors1.txt


In the script where-object will get the input from get-splogevent and process it.


Check here for detailed information on where-object.

FL(Format-List):

FL is an alias for Format-List, where you can format the out results.

To check how FL works run the below command without FL.

#Example with out using Format-List

Get-service

Status   Name               DisplayName                          
------   ----               -----------                          
Running  ADAM_ADAMAD        ADAMAD                               
Running  ADWS               Active Directory Web Services        
Running  AeLookupSvc        Application Experience               
Stopped  ALG                Application Layer Gateway Service    
Stopped  AppFabricCachin... AppFabric Caching Service            
Running  AppFabricEventC... AppFabric Event Collection Service   
Running  AppFabricWorkfl... AppFabric Workflow Management Service
Running  AppHostSvc         Application Host Helper Service

The above command gives you only three columns by default, but if you want more details you need to use the Format-List.

#Example using Format-List

Get-service | FL

Name                : ADAM_ADAMAD
DisplayName         : ADAMAD
Status              : Running
DependentServices   : {}
ServicesDependedOn  : {EventSystem}
CanPauseAndContinue : False
CanShutdown         : True
CanStop             : True
ServiceType         : Win32OwnProcess


I hope now you have understood the complete script that is required to find the error information using powershell command based on correlation Id.

Powershell Scripts for various issues in SharePoint:

Please check below articles for powershell scripts to resolve various types of issues in SharePoint.

Conclusion:

In this post you have seen how to use get-splogevent to get the ULS logs information.

Importance of get-help, Pipeline symbol, where-object, Format-list Powershell commands and writing output to a text file.


› Powershell

About Author

Devendra Velegandla is a four-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2017) for Office Servers and Services MVP and  SharePoint Server.He received the MCC award for his contributions in Microsoft MSDN/TechNet forums.He loves sharing articles, videos and tutorial on SharePoint and Office 365.


If you found this post helpful, please share with your friends!!


Join 5,500 subscribers and receive instant access to

Devendra's Library of Resources for SharePoint Developers