Hello All,
I’ve been working on a script to retrieve the following information from scom:
from a server name or a list of servers, I need to extract the following
- rules and monitors
- Management pack related to those rules and monitors
- configuration settings and thresholds for those rules and monitors
- Targets where the rules and monitors were applied
and lastly, export all these to get the information on a CSV file, it’s been extremly complicated to do it, because when I get some information is complicated to understand or even explained, so I will post the last script what I’m using and hopefully some of you guys can provide guidence, I’ll really appreciate it.
Thanks in advance to everyone.
$ErrorActionPreference = "Stop"
try {
# Cargar la lista de servidores
$servers = Get-Content -Path "servers.txt"
if (-not $servers) {
throw "the file is empty"
}
} catch {
Write-Error "error loading the server list: $_"
exit 1
}
foreach ($server in $servers) {
try {
# Obtener los grupos a los que pertenece el servidor
$groups = Get-SCOMGroup | Where-Object { $_.Name -like "*$server*" }
if (-not $groups) {
throw "there are not groups for the following server $server."
}
} catch {
Write-Warning "Warning: $_"
continue
}
try {
# Obtener las reglas aplicadas
$rules = Get-SCOMRule | Where-Object { $_.Target -like "*$server*" }
if (-not $rules) {
throw "there are no rules applied to this server $server."
}
} catch {
Write-Warning "Warning: $_"
continue
}
foreach ($rule in $rules) {
try {
# checking properties of the rule
$thresholds = $rule.Configuration -or "no configuration"
$monitoringTarget = $rule.Target.Name -or "no available"
$managementPack = $rule.ManagementPack.Name -or "no available"
} catch {
Write-Warning "Error to get configuration details for the rule: $_"
continue
}
# adding information to the array
$results += [PSCustomObject]@{
Server = $server
Groups = ($groups | Select-Object -ExpandProperty DisplayName -join ", ")
RuleName = $rule.DisplayName
Thresholds = $thresholds
MonitoringTarget = $monitoringTarget
ManagementPack = $managementPack
}
}
}
try {
$results | Export-Csv -Path "ServerMonitoringDetails.csv" -NoTypeInformation -Delimiter ";"
Write-Host "The information has been exported successfully to 'ServerMonitoringDetails.csv'."
} catch {
Write-Error "Error to export the results to the CSV file: $_"
exit 1
}
Write-Error "Error Detected: $_" | Out-File -Append -FilePath "ErrorLog.txt"
if (-not (Get-Module -Name OperationsManager)) {
Import-Module -Name OperationsManager -ErrorAction Stop
}
This is the error that I’m getting when I ran the script I pasted.
Select-Object : A parameter cannot be found that matches parameter name 'join'.
At C:\XXXXX\RportingServers-v2EH.ps1:52 char:84
+ ... = ($groups | Select-Object -ExpandProperty DisplayName -join ", ")
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
I already edid the post hope I done correctly… my apologies