Ci-dessous la version Rapport Html du script de l’état des instances d’une liste de classe.
#SCOM - SCRIPT DE REQUETE D'ETAT DES OBJETS D'UNE LISTE DE CLASSE (AVEC GENERATION RAPPORT HTML)
#Variables
$MGroup = "MyGroup"
$MS= "MyMS"
$cred = Get-Credential "MyDomain"
#Liste de classe a recuperer
$ClassList = ('SQL DB Engine','SQL Database','SQL DB File','SQL Agent','SQL Reporting Services','SQL Analysis Services')
$backcolor = "#E0ECF8"
#Import du module SCOM
try
{
Import-Module -Name OperationsManager -ErrorAction stop
}
catch
{
write-host -ForegroundColor red "Erreur lors de l'import du module SCOM"
}
#Connection au management group $MGroup
New-SCOMManagementGroupConnection -ComputerName $MS -Credential $cred
#Recuperation des classes
$MonitoringClasses = $ClassList | foreach {Get-SCOMClass -DisplayName $_}
if ($MonitoringClasses -eq $null)
{
write-host "ERROR - UNABLE TO RETRIEVE CLASSES" -ForegroundColor red
}
$report = "<style>BODY{background-color:$backcolor;}</style>"
$report = $report + "<br/>"
$report = $report + "############################################################################## <br/>"
$report = $report + "SCOM Management Group: <b>$MGroup</b> <br/>"
$report = $report + "############################################################################## <br/><br/>"
#Recuperation des instances de la classe
foreach ($class in $MonitoringClasses)
{
$MonitoringObjects = $class | Get-SCOMClassInstance -erroraction silentlycontinue | Sort-Object -Descending -Property HealthState
$classdisplayname = $class.displayname
$report = $report + "  **************************************************************** <br/>"
$report = $report + "  *** OBJECTS OF CLASS <b>$classdisplayname</b> <br/>"
$report = $report + "  **************************************************************** <br/>"
$report = $report + "  --- $(get-date -Format F) --- <br/><br/>"
$report = $report + "  NUMBER OF OBJECT: $($MonitoringObjects | measure-object | select-object -property count -expandproperty count) <br/><br/>"
$report = $report + "  STATE ---------- OBJECT <br/><br/>"
foreach ($object in $MonitoringObjects)
{
switch ($object.HealthState)
{
"Success" {$report = $report + $("  "; "<font color=#00DF00>" ; $object.HealthState ; "</font>" ; "--------" ; $object.FullName ; "<br/>")}
"Error" {$report = $report + $("  ";"<font color=#FF0000>" ; $object.HealthState ; "</font>" ; "--------" ; $object.FullName ; "<br/>")}
"Warning" {$report = $report + $("  ";"<font color=#FFFF00>" ; $object.HealthState ; "</font>" ; "--------" ; $object.FullName ; "<br/>")}
"Uninitialized" {$report = $report + $("  ";"<font color=#0000FF>" ; $object.HealthState ; "</font>" ; "--------" ; $object.FullName ; "<br/>")}
}
}
$report = $report + "<br/><br/><br/>"
}
ConvertTo-Html -Body $report | Set-Content P:\InstanceList.htm
#Fermeture de la connexion
Get-SCOMManagementGroupConnection | Remove-SCOMManagementGroupConnection
#Execution du html
Invoke-Expression P:\InstanceList.htm