KB: Scripting the Ping MP with PowerShell

When dealing with large amounts of ping targets it is convenient to be able to add/remove them through PowerShell. This kb article contains a sample script for PowerShell (in conjunction with a DLL) to script all your ping targets in SCOM

 

You will need to download the zip containing the DLL here.

After the download unzip the files to for example C:\DevOpsPing\

Change the parameters in the PS script below and run the script on a MS server.

## =======================================================
## Add/change/delete by script a Ping Host and Ping Target
## =======================================================
## Opslogix(c)

# SCOM SDK SERVER
$RMS = "localhost"

# The Ping Source Host to use
$pingSourceHostName = "DEVOM2012SP1-01.contoso.com"

# The Ping Target to check
$pingTargetName = "172.16.10.1"
$pingTargetDisplayName = "Gateway"

# load the assemblies
[System.Reflection.Assembly]::LoadFrom("C:\DevOpsPing\WPF.OpsLogix.IMP.Base.UI.dll");

# Connect to the Management Group
New-SCOMManagementGroupConnection $RMS
$managementGroup = Get-SCOMManagementGroup

# Create an instance of the ping class and load the management group
$PingObj = New-Object OpsLogix.IMP.Base.UI.PowershellPing
$PingObj.loadPing()

# Use the line below to add your ping source node
$PingObj.AddHostInstance($managementGroup,$pingSourceHostName)

# Use the line below to add your ping target
$PingObj.AddTargetInstance($managementGroup,$pingSourceHostName,$pingTargetName,$pingTargetDisplayName)

# Use the line below to remove your ping target
# Uncomment below only if you want to delete the ping target
# $PingObj.RemoveTargetInstance($managementGroup,$pingSourceHostName,$pingTargetName,$pingTargetDisplayName)