Get-SPLogEvent
从统一日志记录服务 (ULS) 跟踪日志返回结果。
语法
Directory
Get-SPLogEvent
[-AssignmentCollection <SPAssignmentCollection>]
[-AsString]
[-ContextKey <String[]>]
[-Directory <String>]
[-MinimumLevel <String>]
[-EndTime <DateTime>]
[-StartTime <DateTime>]
[<CommonParameters>]
File
Get-SPLogEvent
[-AssignmentCollection <SPAssignmentCollection>]
[-AsString]
[-ContextKey <String[]>]
[-MinimumLevel <String>]
[-EndTime <DateTime>]
[-File <String>]
[-StartTime <DateTime>]
[<CommonParameters>]
说明
此 cmdlet 包含多个参数集。 您可以只使用来自一个参数集的参数,也可以不合并来自不同参数集的参数。 若要详细了解如何使用参数集,请参阅 Cmdlet 参数集。
Get-SPLogEvent cmdlet 从符合条件的 ULS 跟踪日志文件返回记录。 如果没有指定参数,则返回所有日志文件的所有记录。 使用 StartTime 和 EndTime 参数可以根据时间范围进行筛选。 建议使用这些参数,以优化此 cmdlet 的性能。
有关适用于 SharePoint 产品的 Windows PowerShell 的权限和最新信息,请参阅 SharePoint Server cmdlet。
示例
示例 1
Get-SPLogEvent -MinimumLevel "Warning"
此示例从默认日志目录中返回严重性大于等于警告的所有日志项。
示例 2
Get-SPLogEvent -Directory "C:\Logs" | Where-Object {$_.Level -eq "Warning"}
此示例从 C:\Logs 目录中的日志文件返回所有警告项。
示例 3
Get-SPLogEvent -StartTime "12/04/2007 17:00" -EndTime "12/04/2007 18:00"
此示例返回特定时间范围(美国的区域性特定范围)内发生的错误项。
示例 4
Get-SPLogEvent -ContextKey @("UserName" ,"SiteName")
此示例返回最新日志文件的内容,并添加指定的 Context Key 数据。
示例 5
Get-SPLogEvent | Where-Object {$_.Level -eq "Error" -and {$_.Area -eq "SharePoint Foundation "}
此示例返回与 SharePoint Foundation 相关的所有错误项。
示例 6
Get-SPLogEvent -ContextKey @("Name") | %{$_.ToString() + "'t" + $_.Context["Name"]}
此示例返回日志文件的内容并添加上下文数据。
参数
-AssignmentCollection
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
管理对象以便正确进行处理。 使用 SPWeb 或 SPSite 等对象可能会耗用大量内存,而且在 Windows PowerShell 脚本中使用这些对象需要正确管理内存。 通过使用 SPAssignment 对象,可以将对象分配给变量,然后在不需要这些对象时对它们进行处理,以释放内存。 在使用 SPWeb、SPSite 或 SPSiteAdministration 对象时,如果不使用分配集合或 Global 参数,则会自动处理这些对象。
在使用 Global 参数时,所有对象均包含在全局存储中。 如果未立即使用对象,或未通过使用 Stop-SPAssignment 命令来处理对象,则可能会发生内存不足的情况。
参数属性
| 类型: | SPAssignmentCollection |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-AsString
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
将每条记录作为单独字符串返回
参数属性
| 类型: | SwitchParameter |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ContextKey
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
指定应将上下文数据添加到指定上下文键的结果,例如: -ContextKey @("UserName", "SiteName")。
参数属性
| 类型: | String[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Directory
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
列出备用目录(除了已配置的 LogLocation 目录之外的任何目录)中的日志文件。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
Directory
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-EndTime
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
键入的值必须是管理语言的区域性特定的有效日期时间格式,如美国英语的日期时间格式为 2/16/2007 12:15:12。
参数属性
| 类型: | DateTime |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-File
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
指定来自查询记录的特定文件。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
File
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-MinimumLevel
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
返回指定级别或以上的记录。 有效值为 Error 或 Warning。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-StartTime
适用:SharePoint Server 2010、SharePoint Server 2013、SharePoint Server 2016 SharePoint Server 2019
键入的值必须是管理语言的区域性特定的有效日期时间格式,如美国英语的日期时间格式为 2/16/2007 12:15:12。
参数属性
| 类型: | DateTime |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。