SCSM PowerShell: Get Configuration Item Information | Quisitive
SCSM PowerShell: Get Configuration Item Information
June 24, 2015
Matthew Dowst
This post is part of a series on Service Manager PowerShell. Be sure to check out the Overview Page for all posts in this series. In the previous post we […]

This post is part of a series on Service Manager PowerShell. Be sure to check out the Overview Page for all posts in this series.

In the previous post we looked at getting work item information using the Get-SCSMClassInstance. This post will expand upon that to include configuration items. Like work items, configuration items are classes in Service Manager, so they also use the Get-SCSMClassInstance cmdlet.

Tips to Find the Class

Just like with the work items you need to start out by determining the name of the class for the item you want to return. However, unlike work items configuration item classes can be a little more difficult to find. This is especially true if you have synced your Operations Manager management packs into Service Manager. For example, in a standard Service Manager environment if I run the Get-SCSMClass cmdlet for any classes that have a display name that contains “computer”, 22 different classes are returned. If that is not bad enough, I ran this same command in a Service Manager environment where I had imported the Operations Manager management packs, and it returned 79 different classes. To be completely honest, sometimes it just takes some trial and error to find the correct class. However, there are a few tricks you can use to help find the correct class.

One way to find the class name is by looking at the views in Service Manager. If you right click on a view and click edit view, it will open the view editing form. If you scroll down to the Criteria section, you will see the display name of the class in the Search for objects of a specific class box.

Another option is to search for classes based on the management pack. For example, if I search for classes that contain “SQL” in their display name, 96 different classes are returned. But if you look at the data returned you’ll notice the column ManagementPackName. By filtering down my results to only include results in the “Microsoft.SQLServer.Library” management pack, I can reduce the number I have to look through to 20.

One last thing you can do to try and determine the configuration item class, is search the default configuration item class (System.ConfigItem) for the item. For example, say you want to find the class for the computer, and you know that there is a computer with the display name of DC01. I can run the Get-SCSMClassInstance to return all configuration items with a display name of DC01. Then, in the output there will be property called “#FullName”. This property is composed of the class name, then a colon followed by the items internal name. Depending on your connectors and how many items you have in your CMDB, you still may receive multiple items returned, but you will be much closer to finding your class.

# Find a CI's Class 
$CIclass = Get-SCSMClass -Name System.ConfigItem 
Get-SCSMClassInstance -Class $CIclass | ?{$_.DisplayName -eq "DC01"} | FT DisplayName, "#FullName" -AutoSize

*PowerShell Tip – You may have noticed in the command above, that I put #FullName in quotes. This is because the hash (#) symbol marks the start of a line comment. Therefore anything after the hash would be ignored. By placing it in between quotes, PowerShell sees it as a string and treats like any other string.

*PowerShell Tip – Sometimes you will notice that PowerShell cuts off the end of the output. This can happen when you return long strings like the #FullName property often is. To prevent this, you have use the AutoSize parameter with the FT cmdlet. The AutoSize parameter will calculate the column sizes and adjust them to best fit your screen. If you are still unable to fit the full output on your screen, you can also use the Wrap parameter to allow word wrapping of the results. For more information on formatting output see the TechNet article Using Format Commands to Change Output View.

Bonus Script

I often find it useful to know what classes a class inherits. To find this, I have written a Function that will parse backwards to find all inherited classes, using the Base property for a class. In the example below, I am using it find all of the classes that the class “Microsoft.Windows.Computer” inherits.

PowerShell
Function GetClassBase($classId)
{
    $class = Get-SCSMClass -Id $classId
    $collection += New-Object PSObject -Property @{Name=$class.Name; DisplayName=$class.DisplayName}
    If($class.Base)
    {
        GetClassBase $class.Base.Id.Guid
    }
    return $collection
}
 
$class = Get-SCSMClass -Name Microsoft.Windows.Computer
GetClassBase $class.Id | FT DisplayName, Name -au

This post demonstrated some tips on how to determine configuration item classes. Be sure to check the Overview Post for more content in this series.