Last active
October 15, 2019 13:48
-
-
Save stegenfeldt/3d7d8d602fd7b322f3fc75bc6a2e3a54 to your computer and use it in GitHub Desktop.
Export-SCOMActiveAlertGenerators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true)] | |
[string[]] $ComputerNames, | |
[ValidateScript({Test-Path -Path $_})] | |
[string] $ExportFolder = ".\" | |
) | |
Import-Module -Name OperationsManager | |
New-SCOMManagementGroupConnection | |
if ($ExportFolder.EndsWith("\")) | |
{ | |
$ExportFolder = $ExportFolder.TrimEnd("\") | |
} | |
$progressActivityName = "Collecting monitoring configurations:" | |
Write-Progress -Activity $progressActivityName -PercentComplete -1 | |
foreach ($computerName in $ComputerNames) | |
{ | |
Write-Progress -Activity $progressActivityName -Status $computerName -PercentComplete -1 | |
$computerClass = Get-SCOMClass -Name "Microsoft.Windows.Computer" | |
$computerObjects = Get-SCOMClassInstance -Class $computerClass | Where-Object {$_.Name -like "$($computerName)*"} | |
if ($null -eq $computerObjects) { | |
#found no windows servers, try linux servers instead | |
$computerClass = Get-SCOMClass -Name "Microsoft.Linux.Computer" | |
$computerObjects = Get-SCOMClassInstance -Class $computerClass | Where-Object {$_.Name -like "$($computerName)*"} | |
} | |
if ($null -eq $computerObjects) | |
{ | |
$filePath = "$ExportFolder\$($computerName).csv" | |
"NOT FOUND IN SCOM" | Out-File -Force -FilePath $filePath | |
continue | |
} | |
foreach ($computerObject in $computerObjects) | |
{ | |
Write-Progress -Activity $progressActivityName -Status "$($computerObject.DisplayName): Getting Data" -PercentComplete -1 | |
$filePath = "$ExportFolder\$($computerObject.Name).csv" | |
Export-SCOMEffectiveMonitoringConfiguration -Instance $computerObject -Path $filePath -RecurseContainedObjects | |
$fileContent = Get-Content -Path $filePath | |
$cleanFileContent = New-Object -TypeName System.Collections.ArrayList | |
Write-Progress -Activity $progressActivityName -Status "$($computerObject.DisplayName): Filtering data" -PercentComplete -1 | |
[int] $longestLine = 0 | |
foreach ($line in $fileContent) | |
{ | |
$longestLine = ($line.Length)+1 | |
$columns = $line.Split("|") | |
if (($columns[4] -eq "Generates Alert" -or $columns[4] -eq "True") -and ($columns[3] -eq "Enabled" -or $columns[3] -eq "True")) | |
{ | |
$cleanFileContent.Add($line.Replace("|","`t")) | Out-Null | |
} | |
} | |
$cleanFileContent | Out-File -Force -FilePath $filePath -Width $longestLine | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added support for linux computers as well.
Made output tab-separated.