SCOM 2007 : Extraction des rules et monitors pour un serveur

Publié: 7 février 2013 dans Microsoft
Tags:, , , , , , , , , ,

###############################################################################
# Exemple usage (run from OpsMgr Command Shell):

#Get-OpsMgrWorkflows_v1.ps1 -agentname « myagent.contoso.com » | export-csv -path c:\temp\workflows.csv

###############################################################################

param ([string]$agentname = $(read-host « Please enter OpsMgr Agent Name »))

function Get-AgentWorkflow($agentname)
{

$taskobj = Get-Task | Where-Object {$_.Name -eq « Microsoft.SystemCenter.GetAllRunningWorkflows »}

# Grab HealthService class object
$hsobj = Get-MonitoringClass -name « Microsoft.SystemCenter.HealthService »
# Find HealthService object defined for named server
$monobj = Get-MonitoringObject -MonitoringClass $hsobj | Where-Object {$_.DisplayName -match $agentname}

#Start Task GetAllRunningWorkflows
$taskOut = Start-Task -Task $taskobj -TargetMonitoringObject $monobj
[xml]$taskXML = $taskOut.OutPut

#Get Workflows
$workflows=$taskXML.selectnodes(« /DataItem/Details/Instance/Workflow »)

#Retrieve Monitors
$monitors = get-monitor

#Retrieve Rules
$rules = get-rule

#Retrieve Discoveries »
#Used the Group-object because there are some discovery rules with the same DisplayName
$discoveries = get-discovery | select-object -Unique

#Get Overrides »
#monitoroverrides = foreach ($monitor in Get-ManagementPack | get-override | where {$_.monitor}) {get-monitor | where {$_.Id -eq $monitor.monitor.id}}
#$rulesoverrides = foreach ($rule in Get-ManagementPack | get-override | where {$_.rule}) {get-rule | where {$_.Id -eq $rule.rule.id}}
#$discoveryoverrides = foreach ($discovery in Get-ManagementPack | get-override | where {$_.discovery}) {get-discovery | where {$_.Id -eq $discovery.discovery.id}}

#Check for each workflow if it’s a Rule or Monitor or Discovery.
foreach ($workflow in $workflows)
{
#Check for Monitor
$monitor = $monitors | where-object {$_.Name -eq $workflow. »#text »}

if ($monitor -eq $null)
{
#Check for Rule
$rule = $rules | where-object {$_.Name -eq $workflow. »#text »}
if ($rule -eq $null)
{
#Check for Discovery
$discovery = $discoveries | where-object {$_.Name -eq $workflow. »#text »}
if ($discovery -eq $null)
{

}
else
{
#Get ManagementPack
$mp = $discovery.getmanagementpack()
#Check if Discovery has an override
#$flag = $discoveryoverrides | Where-Object {$_.DisplayName -eq $discovery.DisplayName}
#if ($flag -eq $null)
#{
#    $override = « false »
#}
#else
#{
#    $override = « true »
#}
$discobject = new-object System.Management.Automation.PSObject
$discobject = $discobject | add-member -membertype NoteProperty -name Type -value « Discovery » -passthru
$discobject = $discobject | add-member -membertype NoteProperty -name DisplayName -value $discovery.DisplayName -passthru
$discobject = $discobject | add-member -membertype NoteProperty -name Description -value $discovery.Description -passthru
#$discobject = $discobject | add-member -membertype NoteProperty -name Override -value $override -passthru
$discobject = $discobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru
$discobject
}
}
else
{
$mp = $rule.getmanagementpack()
#Check if Rule has an override
#$flag = $ruleoverrides | Where-Object {$_.DisplayName -eq $rule.DisplayName}
#if ($flag -eq $null)
#{
#    $override = « false »
#}
#else
#{
#    $override = « true »
#}
$ruleobject = new-object System.Management.Automation.PSObject
$ruleobject = $ruleobject | add-member -membertype NoteProperty -name Type -value « Rule » -passthru
$ruleobject = $ruleobject | add-member -membertype NoteProperty -name DisplayName -value $rule.DisplayName -passthru
$ruleobject = $ruleobject | add-member -membertype NoteProperty -name Description -value $rule.Description -passthru
#$ruleobject = $ruleobject | add-member -membertype NoteProperty -name Override -value $override -passthru
$ruleobject = $ruleobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru
$ruleobject
}
}
else
{
#Get ManagementPack for Monitor
$mp = $monitor.getmanagementpack()
#Check if Monitor has an override
#$flag = $monitoroverrides | Where-Object {$_.DisplayName -eq $monitor.DisplayName}
#if ($flag -eq $null)
#{
#    $override = « false »
#}
#else
#{
#    $override = « true »
#}
$monitorobject = new-object System.Management.Automation.PSObject
$monitorobject = $monitorobject | add-member -membertype NoteProperty -name Type -value « Monitor » -passthru
$monitorobject = $monitorobject | add-member -membertype NoteProperty -name DisplayName -value $monitor.DisplayName -passthru
$monitorobject = $monitorobject | add-member -membertype NoteProperty -name Description -value $monitor.Description -passthru
#$monitorobject = $monitorobject | add-member -membertype NoteProperty -name Override -value $override -passthru
$monitorobject = $monitorobject | add-member -membertype NoteProperty -name ManagementPack -value $mp.DisplayName -passthru
$monitorobject
}
}

}

Get-AgentWorkflow $agentname

Publicités

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s