Automating port monitoring using PowerShell

A while I wrote a blog entry about how you can automate the creation of URL monitoring logic in OpsMgr using PowerShell. One of the questions I have received is "how do you do the same thing for port monitoring ?". Attached is a script that demonstrates how this can be done.

In order to run the script, you need to open the OpsMgr Command Shell and run the following:

CreatePortMonitoring.ps1 -serverName:'' -portNumber:'80' -pollIntervalSeconds:'120' -watcherNodes:"", "" -displayName:'Test URL monitoring' -targetMP:'Port Monitoring MP'

Note: If you specify the interval less than 1 minute, the monitoring should still work but you will not be able to load the configuration page and will see a UI error.....

In one of my future posts I will try to explain how this scripts works for those of you who want to automate execution of MP templates.

Comments (7)
  1. This is so sweet! This new version of MP Viewer allows you to export data to Excel in addition to the

  2. JoeC says:

    Can you provide the one for a Windows Service using the Management Pack Template?  I think that one would be the most valuable as I have 217 services in my environment..  

  3. borisyan says:

    Hi JoeC,

    Can you send me an email offline with info about the services you need to monitor. There might be some other solutions.

  4. Check out Boris Yanushpolsky's blog ( ). Boris is an SCOM

  5. kfields says:

    anyone run into the following exception:

    Exception calling "ProcessMonitoringTemplate" with "5" argument(s): "The ‘PollIntervalInSeconds’ element is invalid – The value ” is invalid according to its datatype ‘

    ma:unsignedInt’ – The string ” is not a valid UInt32 value."

    At D:opsMgrManagementPacks_scriptsCreatePortMonitoringCreatePortMonitoring.ps1:137 char:30

    • $mp.ProcessMonitoringTemplate( <<<< $template,$configDoc.get_InnerXml(),"PortMon" + [System.Guid]::NewGuid().ToString("N"),$displayName,$pollIntervalSeconds)

    i followed the exact format noted above

Comments are closed.

Skip to main content