Allgemein

Forcing a SCOM discovery with PowerShell (the easy way)

Forcing a SCOM discovery with PowerShell (the easy way)

While working on customer’s site I noticed on couple of occasions that triggering a specific discovery in SCOM costs too much time to the guys from the Operations Team. What they were basically doing is following a procedure, found in a blog post, describing how to manually trigger a SCOM discovery:

SCOM 2012 – Manually triggering a Discovery via the SCOM Console (On Demand Discovery)
https://matthewlong.wordpress.com/2013/01/24/scom-2012-manually-triggering-a-discovery-via-the-scom-console-on-demand-discovery/

As my time is pretty precious I cannot afford to follow this exact procedure every time I want to do a “on demand” discovery, without overriding the discover itself. So what I would like to show in this post is the way I trigger discoveries in SCOM – using a simple PowerShell script. Surprisingly I found the script (it is not written by me) long time ago, while searching for an easy way to accomplish this. Interestingly it was posted as a comment in the exact same article, I already posted above. I guy ( I suppose), named Bradc (Thank You, Bradc, credits to you) posted this piece of code as comment:

“i suppose you know this already; but since you’re already in powershell…
$t=get-scomtask -name Microsoft.SystemCenter.TriggerOnDemandDiscovery
$d=get-scomdiscovery -name Your.Discovery
$o=@{DiscoveryId=$d.id.tostring();TargetInstanceId=$d.target.id.tostring()}
$i=get-scomclass -name Microsoft.SystemCenter.ManagementServer | get-scomclassinstance | ?{$_.displayname –eq ’yourserver ’}
start-scomtask -task $t -instance $i -override $o ”

The only thing, which I did in order to be able to quickly trigger the discovery is to replace the “-Name” parameter with “-DisplayName”. This way I can just go and quickly copy the name of the discovery, which is displayed under the discovery details (“Authoring” pane -> “Management Pack Objects” -> “Discoveries”):

SCOM Discovery

SCOM Discovery Display Name

 

The last thing you need to do is put the name of one of your SCOM management server and run the script. So at the end it looks like this:

$Task = Get-SCOMTask -Name Microsoft.SystemCenter.TriggerOnDemandDiscovery
$Discovery = Get-SCOMDiscovery -DisplayName “Discover Windows 2012 R2 Servers”
$Override = @{DiscoveryId=$Discovery.Id.ToString();TargetInstanceId=$Discovery.Target.Id.ToString()}
$Instance = Get-SCOMClass -Name Microsoft.SystemCenter.ManagementServer | Get-SCOMClassInstance | ? {$_.Displayname –eq ’SCOMMgmtSrv.domain.com’}
Start-SCOMTask -Task $Task -Instance $Instance -Override $Override

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.