Adding New Network Devices to SCOM Using PowerShell

2 minute read

Last week, I needed to write a PowerShell script to add iSCSI SAN devices into SCOM 2007 as network devices. I thought the script would be very straight forward, until I realised there is a limitation using SCOM PowerShell snap-in.

To explain it, let me firstly go through how to do this in SCOM console and then I’ll compare this process with using SCOM PowerShell cmdlets.

So, to add a new network device using SCOM console, it’s pretty easy:

  1. Launch Discovery Wizard and choose “Network Devices”

  2. Enter the network device information

image

  1. Select the device from discovery result and choose a proxy agent for this network device

image

Please note the default proxy agent is set to the management server from previous step. it can be changed by click on Change button

image

It lists all possible proxy agents. There are 3 management servers in my test environment, SCOM01 is my RMS, SCOM02 is a management server and SCOMGW01 is a gateway server located in another untrusted forest. I have highlighted these 3 servers, notice the icon for management servers is different than other normal agents.

  1. continue on and complete the rest steps of the wizard.

Now, let’s look at how to do this in PowerShell:

  1. Get Network Device monitoring class
$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'
  1. Create a new DeviceDiscoveryConfiguration object
$dc = new-devicediscoveryconfiguration -monitoringclass $networkdeviceclass fromipaddress "192.168.1.253" -toipaddress "192.168.1.253"
  1. Define SNMP community string
$encoding = new-object System.Text.UnicodeEncoding
$encodedCommunityString = $encoding.GetBytes("tyang")
$dc.ReadOnlyCommunity = [System.Convert]::ToBase64String($encodedCommunityString)
  1. Default SNMP version is 2, if the network device requires version 1, set the device discovery configuration to use SNMP version 1:
$dc.snmpversion = 1
  1. Define the management server to be used in the discovery
$NWDeviceMS = Get-ManagementServer | Where-object {$_.displayname ieq "SCOM02.corp.tyang.org"}
  1. Start discovery using the management server defined in step 5
$DiscoveryResult = Start-Discovery -managementserver $NWDeviceMS -DeviceDiscoveryConfiguration $dc
  1. If discovery is successful, add the device into SCOM.
if ($discoveryresult.monitoringtaskresults[0].status -ieq "succeeded")
{
#code to add the device into SCOM
}

Well, here’s the issue:

if you use the Add-RemotelyManagedDevice cmdlet, you have to use a SCOM AGENT as the proxy agent. You CANNOT choose a management server as the proxy agent for the network devices you are about to add.

image

image

The management server is not an agent, get-agent cmdlet does not return management servers:

image

And if I use the management server in Add-RemotelyManagedDevice cmdlet, it will fail:

image

Basically, object type mismatch…

So, if we want to use a management server as the proxy agent for network devices, we CANNOT use Add-RemotelyManagedDevice cmdlet. It is a limitation in SCOM PowerShell snap-in. Instead, There is a method in the management server object called “InsertRemotelymanagedDevices”:

image

we have to use this method to add network devices.  Therefore, the script for step 7 should be:

if ($discoveryresult.monitoringtaskresults[0].status -ieq "succeeded")
{
$NWDeviceMS.InsertRemotelyManagedDevices($DiscoveryResult.custommonitoringobjects)
}
  1. Check result:

image

image

As you can see, the device has been successfully added.

Leave a comment