Adding an ID or auto incrementing property to default classes

We have lots of Service Manager customers that have comprehensive CMDBs where they store all kind of object types and relationships. When defining your very own classes you know that every class should have a key property. Often this is property is called something like “ID” and will contain an auto incrementing value, e.g. “Car1”, “Car2” etc. so that you don’t have to take care about setting a unique value for every instance. Default classes also have key properties, but not always a real ID. The windows computer class uses the computer principal name as a key property. This can be confusing when you re-install computers or re-use computer names – this is especially confusing when accounting comes into play. So why not having an auto incrementing ID property there too to uniquely identify assets over time?

First add a new property to an existing class. In this example I use the Windows Computer Class and add a string property called “Computer ID”. The Default value is set to “Comp{0}” and used to automatically set a value. To make sure the value increments automatically, I set the auto increment option to true. The property cannot be set as a key property because this is already defined for this scenario.



Now I seal and import the Management Pack. The property is instantly available. All existing Windows Computer objects will have the default value set, but because the system does not know about the auto incrementing yet, it really just sets the value “Comp{0}” for all existing instances. This makes no sense. So first of all, I want to set a real value for these objects by using a simple script.

import-module smlets
[string]$prefix = “Comp”
[int]$number = “1”

$class = get-scsmclass$
$computers = get-scsmobject -class $class

foreach($computer in $computers)
$computerID = $prefix + $number
set-scsmobject -smobject $computer -property mycomputerid -value $computerid
write-host “Property for computer” $computer.displayname “updated to” $computerid -foregroundcolor yellow

By running this script, all instances now have some value set, e.g. “Comp131”.



Now we are running into a problem. When a new Windows Computer is created manually, the system will auto set a value and use an incrementing number that is already used by another object. The problem is that the script did indeed change the values, but because the objects were already existing objects, the system still thinks that it has to use the first number from the auto increment range.


So before we start creating new Windows Computer objects (either manually, CSV import or by using some connectors), we have to increase the auto increment number to another starting point – higher that the highest number we are already using. This can only be done by a direct database change – nasty, but there’s no other way to do it. Travis Wright, Service Manager guru and my well respected MVP Lead at Microsoft, has written a post long time ago for SCSM 2010, but the procedure is still the same for SCSM 2012. Please keep in mind that this is an absolutely unsupported approach! But when you are deep in Service Manager, you already know that you have to accept that fact – Exchange Connector, IDataItem etc., you know what I mean Smiley

If you run this SQL query against the Service Manager database, you will get a list of all incrementing values from all classes and the next value that will be used.


from ManagedType as MT, ManagedTypeProperty as MTP, AutoIncrementAvailableRange as AIAR

where MT.ManagedTypeId = AIAR.ManagedTypeId and MTP.ManagedTypePropertyId = AIAR.ManagedTypePropertyId


By using another SQL statement, the value can be updated to a value that fits your needs. Make sure you use the correct IDs from the first query.

update AutoIncrementAvailableRange
set FirstAvailableValue = 1000
where ManagedTypeId = ‘4364F5B6-7A8E-549E-4B66-9BECF551B346’ and ManagedTypePropertyId = ‘2CE46CF5-FD34-F16C-FC72-3E51EFF43675’

Now as the new value is set and a new Windows Computer is created, the auto incrementing value should be set correctly.


Easy as 1-2-3, that’s it. Have fun!


About Marcel Zehner

Microsoft Azure MVP
This entry was posted in SCSM and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s