Discovery’s at your demand , yes sir!

27 Apr


This time a short post. But I think this could be useful  for SCOM admins.

The challenge.

We all know that one of the big powers of SCOM is the self maintaining of the monitor targets. SCOM uses discovery’s for this that run at regular intervals. Lets say you install a new SQL database instance on a server that has already a SCOM agent on it. Normally you have to wait for 4 hours before the new database instance is discovered. Yes you can speed this up to restart the SCOM agent but now we have a better way.


First, all the credits go to the SCOM product team it self’s. It seems the feature was already build in but making it globally known was somehow left behind. There is a agent task called ‘Trigger On Demand Discovery’ that can help you out. But how to operate this task can be painful.

The solution

I have written a PowerShell script that does the hard work for you. Running this script and supplying the correct Discovery and target will result in a instantly run of that discovery. So now you don’t have to wait for the discovery interval of 4 hours to trigger.

How it works:

1) You fill in the $OMserver with the SCOM SDK server FQDN.

2) You fill in the $discoveryname with the display name of the discovery rule you want to trigger. Just copy and paste the displayname from your author pane in the scom console. See picture below.


3) You fill in the $targetdisplayname with the name of the main target where this discovery should run. You can find this name by looking at the target from the discovery rule you got from step 2.


And fill this in the inventory view.


The name “servicemanager.systemcenter.local” is the target display name to use.

btw. of course you can use PowerShell to do this for you…

Below the script:

It triggers the discovery task and then waits for the results and displays it. Be sure to look at the output results property because it only is okay when it contains :


The script.

## =======================================================
## Trigger SCOM discovery for a discovery rule and target
## ======================================================
## Michel Kamp

Import-Module operationsmanager
## OM sdk server
## discovery display name
$discoveryname=”Service Manager Management Server Properties Discovery”
## target display name

## —————————————————-
## —————————————————-
# connect to OM server
$credentials = get-Credential
new-ScommanagementGroupConnection -Computer $Omserver -Credential $credentials

# get task to execute
$task=get-scomtask -name Microsoft.SystemCenter.TriggerOnDemandDiscovery
# make override params
$discovery=get-scomdiscovery -DisplayName $discoveryname
$TargetInstanceId= (Get-SCOMClass -Id   $  | Get-SCOMClassInstance | ?{$_.displayname -eq $TargetDisplayName}).ID.Tostring()
$instance=get-scomclass -name Microsoft.SystemCenter.ManagementServer | get-scomclassinstance | ?{$_.displayname -eq $Omserver}
# run the task
$task_run=start-scomtask -task $task -instance $instance -override $override

# wait for result
while ( (get-SCOMTask -Id $task_run.TaskId).Status -eq “Started” )
    write-Output “Waiting…”
    Sleep -Seconds 2
# show task output
get-SCOMTaskResult -BatchID $task_run.BatchId

## —————————————————-
## end script
## —————————————————-

The End.

I already did some more investigation on this topic because I think when you can do it for a discovery you can also do it for every workflow that contains a timed interval trigger module. Can you imagine that you can now trigger every rule or monitor at your demand… so cool and so handy while debugging.  When I have it working I will of course share it with you “the community”.


Michel Kamp

6 Responses to “Discovery’s at your demand , yes sir!”

  1. Workman Estimates August 5, 2013 at 21:23 #

    Hiya! I know this is kinda off topic but I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa?
    My blog covers a lot of the same subjects as yours and I
    believe we could greatly benefit from each other.
    If you are interested feel free to shoot me an e-mail. I look forward
    to hearing from you! Fantastic blog by the way!

  2. MP Author August 16, 2013 at 17:45 #

    Thanks for the post.

    I am trying to write a similar powershell script that runs automatically within a Management Pack I am authoring.

    Yet, I was wondering why we need the $instance object of Microsoft.SystemCenter.ManagementServer

    Is there a way to get that automatically without specifying the name of Operations Manager server?

    Shouldn’t the discovery object instance suffice for running the discovery task again?

    I try the following instead:

    $targetInstance = (Get-SCOMClass -Id $discoveryTargetId | Get-SCOMClassInstance | ?{$_.DisplayName -eq $targetDisplayName})
    $runTask = Start-ScomTask -Task $task -Instance $targetInstance -Override $override

    I get this error:

    Start-SCOMTask : The task cannot be executed against the object(s) because the target of the task does not match any of the classes of the object.
    At C:\WvrService\discoveryTrigger.ps1:33 char:26
    + $runTask = Start-ScomTask <<<< -Task $task -Instance $targetInstance -Override $override
    + CategoryInfo : NotSpecified: (Microsoft.Syste…rtSCTaskCommand:StartSCTaskCommand) [Start-SCOMTask], InvalidOperationException
    + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.StartSCTaskCommand

  3. Kevin Wornell June 30, 2014 at 16:22 #

    I have tried this and I get ‘DISCOVERY_NOT_FOUND’ every time.

    • Michel Kamp June 30, 2014 at 17:36 #

      Hi can you give me the changed parameters and the discovery you want to kickoff


  4. Kevin Wornell July 1, 2014 at 16:28 #

    Here are the defined variables with the server name removed

    Import-Module operationsmanager
    ## OM sdk server
    ## discovery display name
    $discoveryname=”Windows DNS Server 2008 Group Discovery”
    ## target display name
    $TargetDisplayName=”Windows DNS Server 2008 Group”

    and the results

    Trigger On Demand Discovery
    Task Description

    Status: Success
    Scheduled Time: 7/1/2014 11:19:27 AM
    Start Time: 7/1/2014 11:19:26 AM
    Submitted By:
    Run As:
    Run Location:
    Target Type: Health Service
    Category: Maintenance
    This task is used to trigger an on demand discovery

    Task Output:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: