Using PowerShell to get agents and devices out of SCOM 2012

Because a customer needed an export of all network devices currently in monitoring and the list was a bit long I decided to use PowerShell for this purpose. However I regularly see questions about retrieving also agents and Linux agents and network devices through this route, so I thought I write some things down here. They all assume this is run from an Operations Manager Shell, otherwise just import-module OperationsManager to get to it.
Getting SCOM Windows Agents
There is a simple command for this purpose:
For instance to get a list of all SCOM agents and show the display name:
Get-SCOMAgent | Select DisplayName
Command reference can be found here.
Getting SCOM Unix/Linux Agents
Because the above command does not give you the cross plat agents we will have to pull in the Unix or Linux agents through another route. There is no get-crossplatagent command so we use the generic route for this. We will be looking for instances of a class.
Now assume we do not know exactly which class to look for, but we can have a guess. I am trying the following commands:
get-scomclass -Displayname “Linux*”
get-scomclass -Displayname “Unix*”
This will give us two relatively short lists of classes starting with Linux or Unix. The one on top of the Unix list looks like our preferred target: UNIX/Linux Computer. We use the displayname. So now we have our class we can pull in the instances of that class and show the displaynames of these to get our list of Unix and Linux agents.
get-scomclass -Displayname “UNIX/Linux Computer” |get-scomclassinstance | select Displayname
Command reference for get-scomclass can be found here.
COmmand reference for get-scomclassinstance can be found here.
Getting SCOM monitored network devices
In the same way as the command to find crossplat agents we can also get our network devices. The class we are looking for is Network Device.
get-scomclass -Displayname “Network Device” | get-scomclassinstance
So now we can play around with the set and show certain fields. A posting from Stefan Stranger gives more insight. I will use an adjusted example from there. These two commands combined give us the name and IP address and AccessMode type (ICMP, SNMP or both) of our monitored network devices:
$MyDevices = get-scomclass -Displayname “Network Device” | get-scomclassinstance
$MyDevices | select DisplayName,@{Label=”SNMPAddress”;Expression={$_.'[System.NetworkManagement.Node].SNMPAddress’}},@{Label=”AccessMode”;Expression={$_.'[System.NetworkManagement.Node].AccessMode’}}
Well, in this case I wanted to export all the fields and not just these three to a CSV file for playing with. So here goes:
$MyDevices = get-scomclass -Displayname “Network Device” | get-scomclassinstance
$MyDevices | select * | Export-CSV -notype C:\Scripts\networkexport.txt
Alright, now we have an exported CSV for playing with.
Command reference for Export-CSV can be found here.
Getting Windows based SCOM agents is very simple as there is a cmdlet for it already.
Getting monitored network devices and Unix?linux agents requires an additional step, but is still easy to do.
Bob Cornelissen