Configuration Script

SCOM 2012 – Getting SCOM SNMP Device Properties in PowerShell

Have you ever tried to access a network device respectively network device properties in SCOM using PowerShell? Let’s say you want to access the network device’s IP address, vendor or description for using in a script? Well, I am sure you will run into a problem which you probably don’t expect. You might think, easy, I just run a cmdlet and select the IP address property of the object. Well, nope, that will not work…

Ok, let’s have a look at the device in SCOM. This is my network device…

image

Notice here, the IP address is located as “SNMP Agent Address” and also other interesting properties like the “System Object ID” which is the device’s OID, the “Device Key” which is the device’s MAC address or “Description”. How can we access those values in PowerShell?

Let’s start, first we need to get the class of the network devices…

$class = Get-SCOMClass -name “System.NetworkDevice”

Next we are going to get the network object itself. Because I just have one device in my environment I just run the following command.

$device = Get-SCOMMonitoringObject -Class:$class

If you would have more then one device you would need to specify an object by running a command like where you e.g. select “Switch01”

$device = Get-SCOMMonitoringObject -Class:$class | Where-Object {$_.DisplayName –eq “Switch01”}

As a next step we need to look at the members of the $device variable/object. For that reason we will run the following command…

$device | Get-Member

image

As we can see our $device object has a lot of methods and properties.

Ok, cool. If we scroll a little bit more down we find the interesting part…

image

As you can see the values we are looking for like description, IP address or MAC address are not like regular properties. Instead those are members of another type called NoteProperty. What is a NoteProperty? Basically it as a member type which contains pairs of keys or names and values or in other words a collection of object members.

In this example here we have “Description” and the value “Zywall 2 Plus”…

image

Now, how can we access those values? It is not very difficult if you know how to do it. You might first try something like this which will not work…

image

Yesterday I had an interesting discussion with MVP Marcel Zehner where he had a similar problem and he showed me how he solved it. Thank’s Marcel for your valuable input. There is also a good post on a MSDN blog which shows how to do it.

The magic keyword is –ExpandProperty. Let’s run the command….

$description = $device | Select-Object -ExpandProperty *.Description

$description.value

To expand the collection of object members we need to provide the –ExpandProperty switch after the Select-Object statement. In this case I expanded the *.Description NoteProperty which is an abbreviation for [System.NetworkManagement.Node].Description. Now you can see that the value we are looking for is stored in the Value property as “Zywall 2 Plus” and this time it is a “real” property…

image

Or if you need to get the IP address…

$IP = $device | Select-Object -ExpandProperty *.SNMPAddress

$IP.value

image

You will find plenty of examples on the internet, now you know what to look for and what it is all about.

I hope you will find this post helpful and saves you some time…

One Reply to “SCOM 2012 – Getting SCOM SNMP Device Properties in PowerShell

  1. just a different way to do this, since the *. leaves a little gap if there are two properties the same.

    $device=get-scomclass -name microsoft.systemcenter.managementserver | get-scomclassinstance | select -last 1
    $v='[Microsoft.SystemCenter.HealthService].Version’
    $device.$v.value

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.