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.

Here are few example which will help to create a custom dashboard.

1. Populating Dashboard from a CSV file

$File = "C:\Temp\SCOMMPList.csv"
$computers = @()
import-csv $File | ForEach-Object{$computers += $_.Name}
$Computers
$i = 1
foreach ($computer in $computers)  
{  
  $Datas = import-csv $File
  Foreach ($Data in $Datas)
  { 
  If ($Data.Name -like $computer)
  {
$dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz")
$dataObject["Id"] = $computer.ToString()
$dataObject["CustomColumn"]=$i
$dataObject["Name"] = $computer
$dataObject["Version"] = $Data.Version
$dataObject["DisplayName"] = $Data.DisplayName
$dataObject["Sealed"] = $Data.Sealed
$ScriptContext.ReturnCollection.Add($dataObject) 
$i++
}
} 
}

2. Populating Dashboard from a text file

$File = "C:\Test.log" 
$inputobject =Get-Content $File | ForEach{ "{0,5} {1}" -f $_.ReadCount,$_ }
        foreach ($line in $inputobject)
        {
            $dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz")
            $dataObject["Id"] = $line.ToString()
            $dataobject["Log"]= $line
            $ScriptContext.ReturnCollection.Add($dataObject)
        }

3. SCOM Agent Server Health state

$class = Get-SCOMClass -Name Microsoft.Windows.Computer 
$Computers = @()
Get-SCOMClassInstance -Class $class | ForEach-Object{$computers += $_.DisplayName} 
$i=1 
foreach ($computer in $computers) 
{
$Datas = Get-SCOMClassInstance -Class $class
Foreach ($Data in $Datas)
{ 
If ($Data.DisplayName -like $computer)
{
$dataObject=$ScriptContext.CreateInstance("xsd://foo!bar/baz")
$dataObject["Id"] = $computer.ToString()
$dataObject["CustomColumn"]=$i 
$dataObject["Name"] = $computer
$dataObject["Path"] = $Data.FullName
$dataObject["IsAvailable"] = $Data.IsAvailable
$dataObject["DisplayName"] = $Data.DisplayName
$dataObject["InMaintenanceMode"] = $Data.InMaintenanceMode 
$ScriptContext.ReturnCollection.Add($dataObject) 
$i++ 
}
}
}

And you also can find few examples here.

New PowerShell Grid Widget Walkthrough | Microsoft Docs

Create a PowerShell Grid Widget dashboard to display Pending Restart status – PowerSQL – Bringing PowerShell and SQL together for the best of both worlds. (randomnote1.github.io)

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwiz3N7hjsvuAhU6zjgGHSyGCzwQFjAAegQIARAC&url=https%3A%2F%2Fmsdnshared.blob.core.windows.net%2Fmedia%2FTNBlogsFS%2Fprod.evol.blogs.technet.com%2Ftelligent.evolution.components.attachments%2F01%2F4616%2F00%2F00%2F03%2F62%2F79%2F94%2FNew%2520Widgets.docx&usg=AOvVaw3MnBudy493UXf6XqP4W09V

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *