Le script ci-dessous génère un rapport formaté dans la ligne de commande, de l’état des instances d’une liste de classe.
#SCOM - SCRIPT DE REQUETE D'ETAT DES OBJETS D'UNE LISTE DE CLASSE
#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')
#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
}
write-host "#################################################### `n"
write-host "SCOM Management Group: $MGroup `n"
write-host "#################################################### `n`n"
#Recuperation des instances de chaque classe
foreach ($class in $MonitoringClasses)
{
$MonitoringObjects = $class | Get-SCOMClassInstance -erroraction silentlycontinue | Sort-Object -Descending -Property HealthState
write-host -BackgroundColor white -ForegroundColor blue " **************************************************************** `n"
write-host -BackgroundColor white -ForegroundColor blue " *** OBJETS DE LA CLASSE "$class.displayname" `n"
write-host -BackgroundColor white -ForegroundColor blue " **************************************************************** `n`n"
write-host " --- $(get-date -Format F) --- `n`n"
write-host " NUMBER OF OBJECT: $($MonitoringObjects | measure-object | select-object -property count -expandproperty count) `n`n"
write-host " STATE ----------------- OBJECT`n`n"
foreach ($object in $MonitoringObjects)
{
switch ($object.HealthState)
{
"Success" {write-host " " -NoNewline ; write-host -ForegroundColor green $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ; write-host $object.FullName}
"Error" {write-host " " -NoNewline ; write-host -ForegroundColor red $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
"Warning" {write-host " " -NoNewline ; write-host -ForegroundColor yellow $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
"Uninitialized" {write-host " " -NoNewline ; write-host -ForegroundColor blue $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
}
}
"`n"
}
#Fermeture de la connexion
Get-SCOMManagementGroupConnection | Remove-SCOMManagementGroupConnection
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
Le script ci-dessous génère un rapport formaté dans la ligne de commande, de l’état des instances d’une liste de classe.
#SCOM - SCRIPT DE REQUETE D'ETAT DES OBJETS D'UNE LISTE DE CLASSE
#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')
#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
}
write-host "#################################################### `n"
write-host "SCOM Management Group: $MGroup `n"
write-host "#################################################### `n`n"
#Recuperation des instances de chaque classe
foreach ($class in $MonitoringClasses)
{
$MonitoringObjects = $class | Get-SCOMClassInstance -erroraction silentlycontinue | Sort-Object -Descending -Property HealthState
write-host -BackgroundColor white -ForegroundColor blue " **************************************************************** `n"
write-host -BackgroundColor white -ForegroundColor blue " *** OBJETS DE LA CLASSE "$class.displayname" `n"
write-host -BackgroundColor white -ForegroundColor blue " **************************************************************** `n`n"
write-host " --- $(get-date -Format F) --- `n`n"
write-host " NUMBER OF OBJECT: $($MonitoringObjects | measure-object | select-object -property count -expandproperty count) `n`n"
write-host " STATE ----------------- OBJECT`n`n"
foreach ($object in $MonitoringObjects)
{
switch ($object.HealthState)
{
"Success" {write-host " " -NoNewline ; write-host -ForegroundColor green $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ; write-host $object.FullName}
"Error" {write-host " " -NoNewline ; write-host -ForegroundColor red $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
"Warning" {write-host " " -NoNewline ; write-host -ForegroundColor yellow $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
"Uninitialized" {write-host " " -NoNewline ; write-host -ForegroundColor blue $object.HealthState -NoNewline ; write-host " -------- " -NoNewline ;write-host $object.FullName}
}
}
"`n"
}
#Fermeture de la connexion
Get-SCOMManagementGroupConnection | Remove-SCOMManagementGroupConnection