Get-SPLogEvent
Published: July 16, 2012
Applies to: SharePoint Foundation 2013 | SharePoint Server 2013 Enterprise
Returns results from a Unified Logging Service (ULS) trace log.
Get-SPLogEvent [-AssignmentCollection <SPAssignmentCollection>] [-AsString <SwitchParameter>] [-ContextKey <String[]>] [-Directory <String>] [-EndTime <DateTime>] [-MinimumLevel <String>] [-StartTime <DateTime>]
Get-SPLogEvent [-AssignmentCollection <SPAssignmentCollection>] [-AsString <SwitchParameter>] [-ContextKey <String[]>] [-EndTime <DateTime>] [-File <String>] [-MinimumLevel <String>] [-StartTime <DateTime>]
Parameters
1| Parameter | Required | Type | Description | ||
| AssignmentCollection | Optional | Microsoft.SharePoint.PowerShell.SPAssignmentColletion | Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.
| ||
| AsString | Optional | System.Management.Automation.SwitchParameter | Returns each record as a separate string | ||
| ContextKey | Optional | System.String[] | Specifies that context data should be added to the results for the specified Context Keys, for example: -ContextKey @("UserName", "SiteName"). | ||
| Directory | Optional | System.String | Lists log files from an alternate directory (any directory other than the configured LogLocation directory). | ||
| MinimumLevel | Optional | System.String | Returns records at or above the specified level. The valid values are Error or Warning. | ||
| EndTime | Optional | System.DateTime | The type must be a valid DateTime format that is culture-specific to the administrative language, such as 2/16/2007 12:15:12 for English-US. | ||
| StartTime | Optional | System.DateTime | The type must be a valid DateTime format that is culture-specific to the administrative language, such as 2/16/2007 12:15:12 for English-US. |
| Parameter | Required | Type | Description | ||
| AssignmentCollection | Optional | Microsoft.SharePoint.PowerShell.SPAssignmentColletion | Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.
| ||
| AsString | Optional | System.Management.Automation.SwitchParameter | Returns each record as a separate string | ||
| ContextKey | Optional | System.String[] | Specifies that context data should be added to the results for the specified Context Keys, for example: -ContextKey @("UserName", "SiteName"). | ||
| MinimumLevel | Optional | System.String | Returns records at or above the specified level. The valid values are Error or Warning. | ||
| EndTime | Optional | System.DateTime | The type must be a valid DateTime format that is culture-specific to the administrative language, such as 2/16/2007 12:15:12 for English-US. | ||
| File | Optional | System.String | Specifies a specific file to query records from. | ||
| StartTime | Optional | System.DateTime | The type must be a valid DateTime format that is culture-specific to the administrative language, such as 2/16/2007 12:15:12 for English-US. |
Detailed Description
This cmdlet contains more than one parameter set. You may only use parameters from one parameter set, and you may not combine parameters from different parameter sets. For more information about how to use parameter sets, see Cmdlet Parameter Sets.
The Get-SPLogEvent cmdlet returns records from a ULS trace log file that match the criteria. If no parameters are specified, all records from all log files are returned. Use the StartTime and EndTime parameters to filter on a time range. The use of these parameters is recommended to optimize performance of this cmdlet.
Input Types
Return Types
--------------EXAMPLE 1-----------------
Get-SPLogEvent -MinimumLevel "Warning"
This example returns all log entries equal to or more severe than Warning from the default log directory.
--------------EXAMPLE 2-----------------
Get-SPLogEvent -Directory "C:\Logs" | Where-Object {$_.Level -eq "Warning"}
This example returns all warning entries from log files in the C:\Logs directory.
--------------EXAMPLE 3-----------------
Get-SPLogEvent -StartTime "12/04/2007 17:00" -EndTime "12/04/2007 18:00"
This example returns error entries that occurred during a particular time range, which is culture-specific to the United States.
--------------EXAMPLE 4-----------------
Get-SPLogEvent -ContextKey @("UserName" ,"SiteName")
This example returns the contents of the most recent log file and adds the specified context key data.
--------------EXAMPLE 5-----------------
Get-SPLogEvent | Where-Object {$_.Level -eq "Error" -and {$_.Area -eq "SharePoint Foundation "}
This example returns all error entries related to SharePoint Foundation.
--------------EXAMPLE 6-----------------
Get-SPLogEvent -ContextKey @("Name") | %{$_.ToString() + "'t" + $_.Context["Name"]}
This example returns the contents of the log file and adds context data.
Change History
| Date | Description |
|---|---|
| July 16, 2012 | Initial publication |

Note: