DIY Service Manager Analyst Portal – Part 5 – Serial Number Look Up

One of the requested additions after this went live was for technicians to easily find the serial number of a machine on site without having to go into SCCM.  This page takes advantage of our SCCM connector and if the data is correctly imported the technician is  likely to get a hit ad know what machine they are dealing with.  If you’re following a naming convention and a random hard drive fails, you can replace the drive and if it asks for the name you can provide it (as an example).

As always, it is split into HTML (serial.aspx) and C# (serial.aspx.cs) parts…

HTML:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="serial.aspx.cs" Inherits="serial" Debug="true" %>

<html>
<body>
<form id="form1" runat="server">
<p>
Note: this serial number checker polls against the objects imported into Service Manager from Configuration Manager and shows all "active" results. The information found may not be completely up to date and there may be multiple listings.
</p>


<hr />




<div id="serialForm" runat="server">
<p>
<asp:TextBox ID="txtSerial" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="btnSerial" runat="server" OnClick="btnSerial_Click" Text="Search Serial Number" />
</p>
</div>

<div ID="divSerial" runat="server"></div>
</form>
</body>
</html>

C#:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;

[Serializable()]
public class Computer : IComparable<Computer>
{
public String Name { get; set; }
public String Model { get; set; }
public String Manufacturer { get; set; }
public String SerialNumber { get; set; }

public int CompareTo(Computer other)
{
return SerialNumber.CompareTo(other.SerialNumber);
}
}

public partial class serial : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnSerial_Click(object sender, EventArgs e)
{
String sSerialCriteria = String.Format(@"<Criteria xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'>" +
"<Expression>" +
"<SimpleExpression>" +
"<ValueExpressionLeft>" +
"<Property>$Context/Property[Type='Microsoft.SystemCenter.ConfigurationManager.DeployedComputer']/SerialNumber$</Property>" +
"</ValueExpressionLeft>" +
"<Operator>Equal</Operator>" +
"<ValueExpressionRight>" +
"<Value>{0}</Value>" +
"</ValueExpressionRight>" +
"</SimpleExpression>" +
"</Expression>" +
"</Criteria>", txtSerial.Text);
EnterpriseManagementConnectionSettings settings = new EnterpriseManagementConnectionSettings("SCSM SERVER");
settings.UserName = "USER NAME";
char[] pass = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
settings.Password = new System.Security.SecureString();
foreach (char c in pass)
settings.Password.AppendChar(c);
settings.Domain = "DOMAIN NAME";

EnterpriseManagementGroup emg = new EnterpriseManagementGroup(settings);

ManagementPack ciManagementPack = emg.GetManagementPack("Microsoft.SystemCenter.ConfigurationManager", "31bf3856ad364e35", null);

ManagementPackClass ci = emg.EntityTypes.GetClass("Microsoft.SystemCenter.ConfigurationManager.DeployedComputer", ciManagementPack);

EnterpriseManagementObjectCriteria criteria = new EnterpriseManagementObjectCriteria(sSerialCriteria, ci, ciManagementPack, emg);

IObjectReader<EnterpriseManagementObject> serialreader = emg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(criteria, ObjectQueryOptions.Default);

List<Computer> compArray = new List<Computer>();

foreach (EnterpriseManagementObject emop in serialreader)
{
if (emop.Values[12].ToString() == "System.ConfigItem.ObjectStatusEnum.Active")
{
Computer newComp = new Computer();

newComp.Name = emop.Values[15].ToString();
newComp.Manufacturer = emop.Values[10].ToString();
newComp.Model = emop.Values[9].ToString();
newComp.SerialNumber = emop.Values[5].ToString();
compArray.Add(newComp);
}
}

divSerial.InnerHtml = "";

if (txtSerial.Text.Equals("") || txtSerial.Equals(null))
{
divSerial.InnerHtml = "";
}
else
{

var sortResult = compArray.OrderBy(a => a.SerialNumber);
divSerial.InnerHtml = divSerial.InnerHtml + "
";

foreach (Computer comp in sortResult)
{
divSerial.InnerHtml = divSerial.InnerHtml + "<hr />";
divSerial.InnerHtml = divSerial.InnerHtml + "
";
divSerial.InnerHtml = divSerial.InnerHtml + "<p><b>Name:</b> " + comp.Name + "</p>";
divSerial.InnerHtml = divSerial.InnerHtml + "<p><b>Manufacturer:</b> " + comp.Manufacturer + "</p>";
divSerial.InnerHtml = divSerial.InnerHtml + "<p><b>Model:</b> " + comp.Model + "</p>";
divSerial.InnerHtml = divSerial.InnerHtml + "<p><b>Serial Number:</b> " + comp.SerialNumber + "</p>";
divSerial.InnerHtml = divSerial.InnerHtml + "
";
}
}

emg.Dispose();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s