在 SharePoint Server 中檢視診斷記錄View diagnostic logs in SharePoint Server

摘要:學習使用 Windows PowerShell 檢視和篩選記錄事件,以及使用 Out-GridView Cmdlet 檢視和匯出診斷記錄。Summary: Learn to view and filter log events by using Windows PowerShell, and view and export diagnostic logs by using the Out-GridView cmdlet.

您可以在 SharePoint Server 中,使用統一登入服務 (ULS) 記錄檔中的資料來針對伺服器陣列中的問題進行移難排解。依據記錄設定,ULS 記錄檔可以收集各種不同層級的資料。使用 PowerShell 篩選資料、以各種方式顯示資料,並可將資料輸出至資料格,然後用來將資料篩選、排序、分組以及匯出至 Excel 2016。You can troubleshoot problems in the farm by using data from the Unified Logging Service (ULS) logs in SharePoint Server . The ULS logs can collect data at varying levels depending on the logging settings. Use PowerShell to filter the data, display it in various ways, and output the data to a data grid with which you can filter, sort, group, and export data to Excel 2016.

使用 Windows PowerShell 檢視及篩選記錄事件View and filter log events by using Windows PowerShell

您可以使用 PowerShell 檢視及篩選記錄事件,但不可使用 SharePoint 管理中心網站檢視或篩選記錄事件。You can use PowerShell to view and filter log events. You cannot view or filter log events by using the SharePoint Central Administration website.

使用 Windows PowerShell 檢視及篩選記錄事件To view and filter log events by using Windows PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 來授與權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 移至 [SharePoint 管理命令介面]。Go to the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    • 所有追蹤事件All trace events:
    Get-SPLogEvent
    
    • 依層級By level:
    Get-SPLogEvent | Where-Object {$_.Level -eq "Information" }
    
    • 依區域By area:
    Get-SPLogEvent | Where-Object {$_.Area -eq <Area>}
    

    其中, <區域>Area 屬性的值。Where <Area> is the value of the Area property.

    • 依類別By category:
    Get-SPLogEvent | Where-Object {$_.Category -eq <Category>
    

    其中, <類別>Category 屬性的值。Where <Category> is the value of the Category property.

    • 依事件識別碼By event ID:
    Get-SPLogEvent | Where-Object {$_.EventID -eq <EventID>}
    

    其中, <事件識別碼>EventID 屬性的值。Where <EventID> is the value of the EventID property.

    • 依訊息文字By message text:
    Get-SPLogEvent | Where-Object {$_.Message -like "<string>"}
    

    其中, <字串> 是在事件訊息中找到的字串。Where <string> is the string found in the event message.

    • 依程序By process:
    Get-SPLogEvent | Where-Object {$_.Process -like "<Process>"}
    

    其中, <程序>Process 屬性的值。Where <Process> is the value of the Process property.

    根據預設,該命令會從預設 ULS 記錄資料夾中擷取資料。若要檢視及篩選網路上共用資料夾中的追蹤事件,請使用 Get-SPLogEvent Cmdlet 的 Directory 參數。By default, the command retrieves data from the default ULS log folder. To view and filter trace events that are on shared folder on a network, use the Directory parameter of the Get-SPLogEvent cmdlet.

    若要檢視各追蹤事件的詳細資料,請在命令結尾使用 Format-List Cmdlet。例如,To view more details about each trace event, use the Format-List cmdlet at the end of the command. For example,

    Get-SPLogEvent | Where-Object {$_.Area -eq "SharePoint Foundation"} | Format-List
    

如需詳細資訊,請參閱<Get-SPLogEvent>。For more information, see Get-SPLogEvent.

使用 Windows PowerShell Out-GridView Cmdlet 檢視及匯出診斷記錄View and export diagnostic logs by using the Windows PowerShell Out-GridView cmdlet

PowerShell 提供強大且便於使用的功能,在個別的視窗中以可篩選、可搜尋的資料格,顯示 Microsoft PowerShell 命令所產生的表格式資料。您可以使用此資料格檢視記錄事件,並可對資料執行下列作業:PowerShell provides a powerful and easy-to-use feature that displays tabular data resulting from Microsoft PowerShell commands in a filterable, searchable data grid in a separate window. You can use this grid to view log events and to perform the following operations on the data:

  • 依任一欄排序資料。Sort the data by any column.

  • 以群組檢視資料。View the data in groups.

  • 依層級、區域、類別、訊息、事件識別碼或時間戳記篩選資料。Filter the data by Level, Area, Category, Message, Event ID, or Timestamp.

  • 搜尋資料中的任何字串。Search the data for any string.

  • 將列或經排序或篩選的資料匯出至試算表。Export raw or sorted or filtered data to a spreadsheet.

注意

[!附註] Out-GridView Cmdlet 不能與使用 Format 動詞的 Cmdlet 搭配使用。 Out-GridView Cmdlet 會接收物件,而使用 Format 動詞的 Cmdlet 只會傳回格式化的文字。 > 您可使用 Where-Object Cmdlet 檢視資料的子集,同時篩選結果並傳遞至 Out-GridView Cmdlet。例如, Get-SPLogEvent | Where-Object {$_.Area -eq "SharePoint Foundation"} | Out-GridView。 > 如果資料格顯示數百列以上,可能會執行得很慢,尤其是在執行複雜的篩選作業時。若要加速效能,請將資料匯出至 Excel 2016。The Out-GridView cmdlet cannot be used with cmdlets that use the Format verb. The Out-GridView cmdlet receives objects whereas the cmdlets that use the Format verb return only formatted text. > You can view a subset of the data by using the Where-Object cmdlet that filters and passes the results to the Out-GridView cmdlet. For example, Get-SPLogEvent | Where-Object {$_.Area -eq "SharePoint Foundation"} | Out-GridView. > If the grid is displaying more than several hundred rows, it might run slowly, especially if performing complex filtering operations. For faster performance, export the data to Excel 2016.

使用 Windows PowerShell 檢視及篩選診斷記錄To view and filter diagnostic logs by using Windows PowerShell

  1. 確認您具備下列成員資格:Verify that you have the following memberships:

    • SQL Server 執行個體上的 securityadmin 固定伺服器角色。securityadmin fixed server role on the SQL Server instance.

    • 所有要更新之資料庫上的 db_owner 固定資料庫角色。db_owner fixed database role on all databases that are to be updated.

    • 正在執行 PowerShell Cmdlet 之所在伺服器上的系統管理員群組。Administrators group on the server on which you are running the PowerShell cmdlets.

      系統管理員可以使用 Add-SPShellAdmin Cmdlet 來授與權限。An administrator can use the Add-SPShellAdmin cmdlet to grant permissions.

      注意

      [!附註] 如果您不具備上述權限,請連絡安裝程式系統管理員或 SQL Server 系統管理員要求權限。如需 PowerShell 權限的其他資訊,請參閱 Add-SPShellAdminIf you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about PowerShell permissions, see Add-SPShellAdmin.

  2. 移至 [SharePoint 管理命令介面]。Go to the SharePoint Management Shell.

  3. 在 PowerShell 命令提示字元處,輸入下列命令:At the PowerShell command prompt, type the following command:

    Get-SPLogEvent | Out-GridView
    
  4. 若要排序欄,請按一下欄標題。To sort columns, click the column header.

  5. 若要搜尋特定的字串,請在 [篩選] 方塊中輸入的字串。所有的欄和列上執行搜尋。若要清除搜尋,請按一下 [ X]。To search for a specific string, type the string in the Filter box. Search is performed over all columns and rows. To clear the search, click X.

  6. 若要篩選上只有一個準則的資料,請在 [搜尋] 方塊中輸入下列:<屬性名稱>:<值>。例如,若要搜尋的所有記錄 SharePoint Foundation 2013 所引發的項目,請輸入下列:] 區域中: SharePoint Foundation。若要清除篩選,請按一下 [ X]。To filter data on only one criterion, type the following in the Search box: <property name>:<value>. For example, to search for all log entries raised by SharePoint Foundation 2013, type the following: Area:SharePoint Foundation. To clear the filter, click X.

  7. 若要使用多個準則,或是使用具有「包含、開始於、結束於」或其他方法的準則篩選資料:To filter data by using more than one criterion or by using criteria with "contains, begins with, ends with" or other methods:

  8. 按一下 [新增準則] 按鈕。Click Add criteria button.

  9. 按一下您想要當做篩選依據,屬性的核取方塊並再按一下 [新增]。Click the check box for the properties that you want to filter on, and then click Add.

  10. 按一下 [變更為不同的篩選器方法會包含。可用的方法且包含不包含開始與等於不等於結束於空的是不是空的Click contains to change to a different filter method. The methods that are available are contains, does not contain, starts with, equals, does not equal, ends with, is empty, and is not empty.

  11. 在文字方塊中輸入值。Type a value in the text box.

  12. 針對您在步驟 "b" 中選取的每個屬性,重複步驟 "c" 及 "d"。Repeat steps "c" and "d" for each property that you selected in step "b".

  13. 指定所有篩選準則之後,隨即顯示符合準則的資料。When all the filtering criteria are specified, the data that satisfies the criteria will appear.

  14. 若要清除特定篩選,請按一下 [ X ] 按鈕。To clear a specific filter, click the X button.

  15. 若要清除所有篩選,請摺疊查詢檢視和 [全部都清除] 按鈕。To clear all the filters, collapse the query view and then click the Clear All button.

    將資料格的資料匯出至試算表To export grid data to a spreadsheet

  16. 選取您要匯出的列。若要選取多列,請按住 Shift 鍵再拖曳以選取一個區塊的列、按住 Ctrl 鍵再按一下滑鼠以選取特定列,或使用 Ctrl+A 以選取所有列。Select the rows that you want to export. You can select multiple rows by using SHIFT+DRAG to select a block of rows, CTRL+CLICK to select specific rows, or CTRL+A to select all rows.

    您也可以先篩選及排序結果,再將資料複製到試算表中。當您排序或篩選資料時,只會複製所產生之可檢視的資料。You can also filter and sort the results before you copy the data into a spreadsheet. When you sort or filter data, only the resulting viewable data is copied over.

  17. 使用 Ctrl+C 複製所選列。Copy the selected rows by using CTRL+C.

  18. 開啟試算表活頁簿頁面,然後使用 Ctrl+V 貼入複製的列。Open the spreadsheet workbook page, and then paste the copied rows into it by using CTRL+V.

如需詳細資訊,請參閱<Out-GridView>(https://go.microsoft.com/fwlink/p/?LinkId=181248) 和<Out-GridView Revisited>(https://go.microsoft.com/fwlink/p/?LinkId=181249)。For more information, see Out-GridView (https://go.microsoft.com/fwlink/p/?LinkId=181248) and Out-GridView Revisited (https://go.microsoft.com/fwlink/p/?LinkId=181249).