Microsoft has shipped the long awaited and promised widgets for building new and cool dashboards. The System Center Operations Manager Team has released a short documentation and a bit more details you will find on TechNet Wiki:
One information which you won’t find is, that these widgets are NOT ONLY available for SCOM 2012 R2 UR2 but also in SCOM 2012 SP1 UR6. Microsoft has shown it at Tech Ed NA 2014 on a slide in session DCIM-B329
As I am exploring these widgets, there are two widgets I really got into (and as I have seen also others) because they will allow you to do almost anything. One is the PowerShell Grid Widget and the other is the PowerShell Web Browser Widget.
My goal is to click onto a computer object and then displaying its location on a map like Bing Maps or Google Maps. To realize this, I remembered that you can provide latitude and longitude to the SCOM 2012 agent to set its location. So why not use this information? It seems that Tao Yang had a similar idea as I, but was choosing the more complicated way 🙂 .
Find latitude / longitude
First you need to figure out what the latitude and longitude of your location is. You could use for example http://www.latlong.net/ to get the values, e.g. Bern (in Switzerland).
Configure the location and agent
Open the PowerShell command and set the location…
New-SCOMLocation -DisplayName “Bern” -Latitude 46.94 -Longitude 7.44
Next assign the location to the SCOM agent e.g. Bern…
$location = Get-SCOMLocation -DisplayName “Bern”
$agent = Get-SCOMAgent -Name “DC01.bigfirm.com”
Set-SCOMLocation -Location $Location -Agent $agent
I repeated these steps for another agent called VMM2012R2.bigfirm.com and assigned the “New York” location.
Build the dashboards
Next we create a 3 cell dashboard, basically the frame…
Build computer widget
For the top left cell add the PowerShell Grid Widget…
Then I added the following script…
After you finish the widget, it will look like this…
Build bing maps widget
The idea is, that you select a computer from the first widget and then get in context the location. In order to do this, add in the lower large space the PowerShell Web Widget
…and add the following code…
If you click on VMM2012R2.bigfirm.com server bing maps will show the location…
Build Google maps widget
Of course you can also use Google maps, which has a clearer appearance out of the box. To utilize it you need to change the code a bit, like this…
If you click VMM2012R2.bigfirm.com again, it will look like this…
As you can see, we are just using the built in functionality of the SCOM agent to get its location displayed on any map by providing a properly formatted URL. In addition I was able to list the computers in a separated widget and add a custom column with the location / city name. To display the logos I simply used the Image Widget.
This is just touching the surface of all the possibilities. I am not sure if there is an easy way to debug the widgets, but I started just writing log files to figure out what exactly is going on. Hopefully Microsoft will provide some more tutorials.
I put the code for download on OneDrive.
Have fun!
Nice post Stefan. this is certainly a much simpler approach as there are no class definition and discoveries involved. It will probably suit the needs for environments which have fewer sites.
Thanks for sharing with us.
Tao
Hello All,
I keep getting a “You cannot call a method on a null-valued expression.” When I attempt to build the Windows Powershell Grid console. Has anyone else seen this issue? It is throwing the error on the line:
“$dataObject = $ScriptContext.CreateFromObject($computer, “Id=Id,HealthState=HealthState,DisplayName=DisplayName”, $null)”
Thanks for any insight!
MP
Hi
I would guess that your $Computer object is empty. Try to open the SCOM console on the Management Server and check if the error still exists, then execute in a PowerShell window
$class = Get-SCOMClass -Name Microsoft.Windows.Computer
$computers = Get-SCOMClassInstance -Class $class
Do you have any objects in $omputers? If so execute in the same window:
foreach ($computer in $computers)
{
Write-Host $computer
}
What do you see?
Cheers,
Stefan
Thanks Stefan,
Yes I did that. I am getting:
False back as a result. Not sure what “False” is referencing.
The Get-SCOMAgent and Get-SCOMLocation commands are also completing successfully. It is only when I call the first $dataObject line that things begin to fall apart. I’ve tried removing the “$null” from the first $dataObject line, but that did not help.
Here is the full error:
You cannot call a method on a null-valued expression.
At E:Scriptslist-computers.ps1:13 char:2
+ $dataObject = $ScriptContext.CreateFromObject($computer, “Id=Id,HealthState=Hea …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot index into a null array.
At E:Scriptslist-computers.ps1:14 char:2
+ $dataObject[“CITY”]=$city[6].value
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Any insights would be appreciated. If you’re stumped no worries, I will keep investigating as well and post any resolutions I find.
Hi
Hmm I am not sure HOW you execute the script BUT the $ScriptContext helper object exists only within the Dashboard. You cannot execute the script just in a PowerShell window YOU MUST add a PowerShell Grid Widget and copy paste the code.
Make sure you set the SCOM agent location on the agent for the computers as described in the post.
This might help also http://social.technet.microsoft.com/wiki/contents/articles/21625.scriptcontextobject.aspx
Cheers,
Stefan
Hello Stefan, just realized I used greater than and less than on part of my response. I am getting:
“HealthState” “False” “ComputerName” as a response from $computer. Hope that helps.
Hello Stefan,
Worked like a champ. I think I need a lesson in patience! It only took a few minutes for the list to populate, so I must have been closing out of the screen before it actually populated the first few times.
Thanks for the guidance! Works great! For anyone else that is as impatient as I am: put in the code and grab a coffee! It will be populated once you get back.
hello ,
how can I make the status of computers or groups shown on the map directly green or red
Hi
You just need to change the classes in the code to use the SCOM group.
Cheers,
Stefan
Hi Stefan – I have followed this process but the powershell does not render the citylocation for some reason. Is it possible to create dynamic groups based upon the location set using Set-SCOMLocation?