Adding New Network Devices to SCOM Using PowerShell

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

3. 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.

4. 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'

2. Create a new DeviceDiscoveryConfiguration object

$dc = new-devicediscoveryconfiguration -monitoringclass $networkdeviceclass –fromipaddress “192.168.1.253” -toipaddress “192.168.1.253”

3. Define SNMP community string

$encoding = new-object System.Text.UnicodeEncoding

$encodedCommunityString = $encoding.GetBytes("tyang")

$dc.ReadOnlyCommunity = [System.Convert]::ToBase64String($encodedCommunityString)

4. 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

5. Define the management server to be used in the discovery

$NWDeviceMS = Get-ManagementServer | Where-object {$_.displayname –ieq “SCOM02.corp.tyang.org”}

6. Start discovery using the management server defined in step 5

$DiscoveryResult = Start-Discovery -managementserver $NWDeviceMS -DeviceDiscoveryConfiguration $dc

7. 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)
}

8. Check result:

image

image

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

2 comments

Leave a Reply

%d bloggers like this: