New PowerShell Grid Widget Walkthrough

With the release of UR2 for System Center 2012 R2 we included updates for the Widgets which allow you to create richer dashboard visualization within Operations Manager.

More information about the new list of Widgets can  be found here: https://social.technet.microsoft.com/wiki/contents/articles/24133.operations-manager-dashboard-widgets.aspx

One of the more interesting new Widgets in my opinion are the PowerShell Grid Widgets:

  • PowerShell Grid Widget
  • PowerShell Web Browser Widget

The PowerShell Grid Widget displays the results of a Windows PowerShell script in a grid.  The script is run when the dashboard is opened and each time the component is refreshed. 

The script will run on the computer with the console and will typically use the Operations Manager SDK (not in this walkthrough) to access a management server and retrieve information from the management group.  It must then use the ScriptContext object to create a Data Object and return it using the ReturnCollection method.

The PowerShell Web Browser Widget displays the output of a web page retrieved by a PowerShell script.  The script is run when the dashboard is opened and each time the component is refreshed.

The script will run on the computer with the console and should create a Data Object using Request type defined in Microsoft.SystemCenter.Visualization.Component.Library.WebBrowser.Schema.  You specify the Url by setting the BaseUrl property.  The request is sent to the site and the resulting output delivered to the dashboard when the ReturnCollection method of the ScriptContext object.

In this blog post I will guide you through the creation of PowerShell Grid Widget to retrieve the latest blog posts from the System Center: Operations Manager Engineering Blog using PowerShell to retrieve the RSS feed for this blog.

Step 1: Create a New Dashboard and Widget

image

Select the layout for this dashboard. In this case we are going to have a single cell dashboard

image

Step 2: Add a Widget to Dashboard created above

image

Select the PowerShell Grid Widget

image

After entering the General Properties for the Widget we need to add the PowerShell script we are going to use for the Grid

image

 [xml]$Feeds = Invoke-WebRequest -Uri "https://blogs.technet.com/b/momteam/atom.aspx"

$Entries = $Feeds.feed.entry | select title, @{LABEL="Published"; EXPRESSION={[datetime]$_.Published} } | Sort-Object -Property Published -Descending

foreach ($Entry in $Entries)
{
 $Title = $Entry.title
 $Published = $Entry.published
 $dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz")
 $dataObject["Id"] = $Title.ToString()
 $dataObject["Title"] = $Title
 $dataObject["Published"] = $Published
 $ScriptContext.ReturnCollection.Add($dataObject)
}

Save the Grid and open the Dashboard in the Monitoring Pane of the Console

image

If you want to learn more about using the new Widgets part of the new UR2 for OM2012 R2 you can download the Word document attached at the New Widgets and Dashboard blog post.

Have fun exploring the new Widgets and Dashboards!

Disclaimer:

This example is provided “AS IS” with no warranty expressed or implied. Run at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of Microsoft.

**Always test in your lab first** Do this at your own risk!! The author will not be held responsible for any damage you incur when making these changes!