Web page displaying amount of SCSM Incidents, Service Requests and Change Requests

This is an example how to make a very easy web page displaying some status information regarding Incidents, Service Requests and Change Requests. The script is very easy to change and modify for your organization.

When being ran the script will create a web page as shown below. Please change the last line in the script and point it to a location where you want to put the web page.

1

Script Code

#################################################################
# Author: Jonathan Andersson systemcenterme.com
# Description: Create a simple web page showing case count
#################################################################

# Empty variable
$IRInt=0
$SRInt=0
$CRInt=0

Import-Module SMLets

$IRClass=Get-SCSMClass -Name System.workitem.Incident$
$CRClass=Get-SCSMClass -Name System.workitem.ChangeRequest$
$SRClass=Get-SCSMClass -Name System.WorkItem.ServiceRequest$ 

$IR=Get-SCSMObject -Class $IRClass -filter “Status -eq 5e2d3932-ca6d-1515-7310-6f58584df73e” # Active
$CR=Get-SCSMObject -Class $CRClass -filter “Status -eq 6d6c64dd-07ac-aaf5-f812-6a7cceb5154d” # In Progress
$SR=Get-SCSMObject -Class $SRClass -filter “Status -eq 59393f48-d85f-fa6d-2ebe-dcff395d7ed1” # In Progress

foreach($IRIin$IR){if($IRI.Priority -eq “1”){$IRInt++}}
foreach($CIin$CR){if($CRI.Priority.DisplayName -eq “High”){$CRInt++}}
foreach($SRIin$SR){if($SRI.Priority.DisplayName -eq “High”){$SRInt++}}

$IRTot=$IR.Count
$SRTot=$SR.Count
$CRTot=$CR.Count

# Get yesterdays date
$date=Get-Date
$DateOld= (Get-Date).AddDays(-1
$DateOldF=Get-Date $DateOld -format G

$IR24Tot=Get-SCSMObject -Class $IRClass -filter “Createddate -gt $DateOldF
$SR24Tot=Get-SCSMObject -Class $SRClass -filter “Createddate -gt $DateOldF
$CR24Tot=Get-SCSMObject -Class $CRClass -filter “Createddate -gt $DateOldF” 

$IR24TotC=$IR24Tot.Count
$SR24TotC=$SR24Tot.Count
$CR24TotC=$CR24Tot.Count 

$a=“<style>”
$a=$a+“BODY{background-color:white;}”
$a=$a+“TABLE{border-width: 1px;border-style: solid;border-color: white;border-collapse: collapse;}”
$a=$a+“TD{border-width: 1px;padding: 0px 5px 0px 5px;border-style: non;border-color: black;background-color:white}”
$a=$a+“TR{border-width: 1px;padding: 0px 5px 0px 5px;border-style: non;border-color: black;background-color:white}”
$a=$a+“</style>” 

ConvertTo-Html -head $a -title “Service Manager” -body
<h2>Service Manager</h2>
<table>
<tr>
<td><h4>All Open</h4></td>
</tr>
<tr>
<td>Incidents:</td><td>$IRTot</td>
</tr>
<tr>
<td>Service Requests:</td><td>$SRTot</td>
</tr>
<tr>
<td>Change Requests:</td><td>$CRTot</td>
</tr>
<tr>
<td><h4>All Open High Priority</h4></td>
</tr>
<tr>
<td>Incidents:</td><td>$IRInt</td>
</tr>
<tr>
<td>Service Requests:</td><td>$SRInt</td>
</tr>
<tr>
<td>Change Requests:</td><td>$CRInt</td>
</tr>
<tr>
<td><h4>Total last 24 hours</h4></td>
</tr>
<tr>
<td>Incidents:</td><td>$IR24TotC</td>
</tr>
<tr>
<td>Service Requests:</td><td>$SR24TotC</td>
</tr>
<tr>
<td>Change Requests:</td><td>$CR24TotC</td>
</tr>
</table>
<br />
<b>Last update:</b> $Date
| Out-File C:\tmp\test.html

Download Script: SCSM_Count_Case

2 Responses to Web page displaying amount of SCSM Incidents, Service Requests and Change Requests

  1. santiago July 24, 2015 at 19:17 #

    good morning , I would make a query, that query would be like for a specific _TierQueue ?

  2. Charlie December 29, 2016 at 00:14 #

    Nice. However, I couldn’t get the webpage to display numbers. It just displays the variable, such as “$IRTotC”. Also, had to add spaces before and after “in” in the foreach statements. In Powershell, if I typed $IRTotC it returns a number, so the script is working. I just can’t figure out what my problem is in the conversion to HTML.

Leave a Reply