Import subscribers into SCOM via PowerShell

Quick post

A client had an existing monitoring system and exported the subscriber address list to CSV.

They wanted some names updated to reflect the DC and existing name, also some subscribers had multiple addresses in the form of an array so I had to get a little creative with PowerShell.

The script I used is below:

$File = "C:\Temp\import.csv"
  $Subscribers = Import-CSV $file
  $Scomserver = "scomserver"

ForEach ($Subscriber in $Subscribers)
  {
  $SubscriberName = $Subscriber.DataCentre + " - " + $Subscriber.Name
  $SubscriberAddress = $Subscriber.Addressees.Split(',')
  $hash = $null
  $hash = @{}
  ForEach ($Address in $SubscriberAddress)
  {
  $hash.add($Address,$Address)
  }
  Add-SCOMNotificationSubscriber -ComputerName $Scomserver -Name "$SubscriberName" -DeviceTable $hash
  }

Example in the CSV:

Name,DataCentre,Addressees
Applications,Sydney,”daniel@domain.com,mary@domain.com”
WebServices,Melbourne,tom@domain.com
Infrastructure,Sydney,”bob@domain.com,mary@domain.com,daniel@domain.com”

import.csv

Run the script
script.run

Check the results in SCOM (filtered by search)
syd

Check the multiple addressees
addressees

 

I ran this on a CSV with approximately 190 subscribers ranging from 1 addressee to 15 addressee’s and it worked a treat!

Ideally you’d want multiple addressees managed by distribution groups as editing in the SCOM Console directly has it’s challenges. This little script helped to bridge the gap and get everything in there as the project had a very tight timeline.. Anyway….

Done!

Enjoy,
Dan

Leave a Reply

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