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:
-
Launch Discovery Wizard and choose “Network Devices”
-
Enter the network device information
- Select the device from discovery result and choose a proxy agent for this network device
Please note the default proxy agent is set to the management server from previous step. it can be changed by click on Change button
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.
- continue on and complete the rest steps of the wizard.
Now, let’s look at how to do this in PowerShell:
- Get Network Device monitoring class
$networkdeviceclass = get-monitoringclass -name 'System.NetworkDevice'
- Create a new DeviceDiscoveryConfiguration object
$dc = new-devicediscoveryconfiguration -monitoringclass $networkdeviceclass –fromipaddress "192.168.1.253" -toipaddress "192.168.1.253"
- Define SNMP community string
$encoding = new-object System.Text.UnicodeEncoding
$encodedCommunityString = $encoding.GetBytes("tyang")
$dc.ReadOnlyCommunity = [System.Convert]::ToBase64String($encodedCommunityString)
- 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
- Define the management server to be used in the discovery
$NWDeviceMS = Get-ManagementServer | Where-object {$_.displayname –ieq "SCOM02.corp.tyang.org"}
- Start discovery using the management server defined in step 5
$DiscoveryResult = Start-Discovery -managementserver $NWDeviceMS -DeviceDiscoveryConfiguration $dc
- 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.
The management server is not an agent, get-agent cmdlet does not return management servers:
And if I use the management server in Add-RemotelyManagedDevice cmdlet, it will fail:
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”:
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)
}
- Check result:
As you can see, the device has been successfully added.
Leave a comment