如何在 Web 主控台中使用 PowerShell 小工具來建立儀表板How to create a dashboard with the PowerShell widget in the Web console

重要

已不再支援此版本的 Operations Manager,建議升級至 Operations Manager 2019This version of Operations Manager has reached the end of support, we recommend you to upgrade to Operations Manager 2019.

在 System Center Operations Manager 1801 版與更新版本中中,Web 主控台會提供管理群組的監視介面,它能在可連線至 Web 主控台伺服器的任何電腦上,使用任何瀏覽器來開啟。In System Center Operations Manager version 1801 and higher, the Web console provides a monitoring interface for a management group that can be opened on any computer using any browser that has connectivity to the Web console server. 下列步驟說明如何在新的 HTML5 Web 主控台中使用 PowerShell 小工具來建立儀表板。The following steps describe how to create a dashboard in the new HTML5 Web console with the PowerShell widget.

指令碼一般將會使用 Operations Manager Cmdlet 從管理群組擷取資訊。The script will typically use the Operations Manager cmdlets to retrieve information from the management group. 它接著必須使用 ScriptContext 物件來建立「資料物件」,然後將該物件新增到 ReturnCollection 屬性中。It must then use the ScriptContext object to create a Data Object and then add that object to the ReturnCollection property. 一般而言,搭配 Silverlight 型 PowerShell 小工具使用時,指令碼是使用名為 $dataObject 的變數所設定,而且此變數存放從 ScriptContext 物件傳回的資料。Typically with the Silverlight based PowerShell widget, scripts were configured with the variable named $dataObject, and this variable held data returned from ScriptContext object. 不過,這個小工具不支援該變數名稱,而且當您嘗試儲存您所做的變更時,將會傳回錯誤。However, this widget does not support that variable name and will return an error when you attempt to save your changes. 以自訂名稱 (例如 $results) 取代此變數。Replace this variable name with a custom name such as $results.

將小工具新增至儀表板Add widget to dashboard

  1. 在任何電腦上開啟網頁瀏覽器並輸入 http://<web host>/OperationsManager,其中 web host 是裝載 Web 主控台的電腦名稱。Open a web browser on any computer and enter http://<web host>/OperationsManager, where web host is the name of the computer hosting the web console.

  2. 從 Web 主控台的左窗格,按一下 [+ 新增儀表板] 。From the left pane in the Web console, click + New dashboard.

    在 Web 主控台中選取 [新增儀表板]

  3. 在 [建立新的儀表板] 頁面上,提供您想要建立之儀表板的名稱和描述。On the Create New Dashboard page, provide a name and description for the dashboard you want to create.

    指定新儀表板的名稱與描述

  4. 您可以在現有未密封的管理組件中,藉由從 [管理組件] 下拉式清單中選取該管理組件來儲存儀表板,或者,您可以按一下 [管理組件] 下拉式清單旁的 [新增] 來建立新的管理組件,藉以儲存儀表板,並提供名稱、描述及版本號碼 (選擇性)。You can save the dashboard in an existing unsealed management pack by selecting the management pack from the Management Pack drop-down list or you can save the dashboard by creating a new management pack by clicking New next to the Management Pack drop-down list and provide a name, description and optionally a version number.

    指定新 MP 的名稱與描述

  5. 當您已完成指定要儲存新儀表板的位置之後,按一下 [確定] 。When you have completed specifying where to save the new dashboard to, click OK.

  6. 在提供新儀表板的名稱和描述之後,按一下 [儲存] 。Click Save after providing a name and description for the new dashboard.

  7. 在空白的空儀表板上,您會在頁面頂端看到儀表板名稱、[新增小工具] 、[編輯儀表板] 、[刪除儀表板] 和 [全螢幕檢視] 選項。On the blank empty dashboard, you see the dashboard name, Add Widget, Edit Dashboard, Delete dashboard and View in fullscreen options on the top of the page. 選取 [新增小工具] 。Select Add Widget.

    新的儀表板畫布

  8. 從 [選取小工具] 下拉式清單中,選取 [PowerShell 小工具]。Select PowerShell Widget from the Select Widget drop-down list.

  9. 在 [PowerShell 小工具] 窗格中,寫下或複製並貼上您的 PowerShell 指令碼到文字方塊中。In the PowerShell widget pane, write or copy and paste your PowerShell script into the textbox.

    輸入 PowerShell 指令碼

    下列範例指令碼會建立已編號的 Windows Computer 物件的表格,並顯示每個項目識別碼、健康情況狀態與顯示名稱。The following sample script creates a table of numbered Windows Computer objects and displays the ID, health state, and display name for each.

    $class = Get-SCOMClass -Name Microsoft.Windows.Computer  
    $computers = Get-SCOMClassInstance -Class $class  
    $i=1  
    foreach ($computer in $computers)  
    {  
        $results=$ScriptContext.CreateFromObject($computer,"Id=Id,HealthState=HealthState,DisplayName=DisplayName",$null)   
        $results["CustomColumn"]=$i   
        $ScriptContext.ReturnCollection.Add($results)   
        $i++   
    }  
    
  10. 為小工具提供名稱描述小工具重新整理間隔 (預設間隔為 5 分鐘),藉以完成設定。Complete the configuration by providing a Name, Description and Widget reefresh interval (default interval is 5 minutes) for the widget. 按一下 [儲存小工具] 以儲存新的儀表板。Click Save Widget to save your new dashboard.

建立小工具之後,它會顯示您指令碼的結果。After the widget has been created, it displays the results of your script.

PowerShell 小工具結果範例

使用 PowerShell 小工具執行的動作Actions with PowerShell widget

利用 PowerShell 小工具,您可以執行如下的動作:With a PowerShell widget, you can perform such actions as:

  • 將警示匯出至 Excel,以供進一步分析Export the alerts to Excel for further analysis

後續步驟Next steps

若要深入了解如何在 Web 主控台中使用狀態小工具來建立儀表板,請參閱如何在 Web 主控台中使用狀態小工具建立儀表板To learn how to create a dashboard in the new web console with the State widget, see How create a dashboard with the State widget in the Web console