Created
June 13, 2018 05:03
-
-
Save Juanito99/ae7f1ec364ec55bfeb316c3e029d20b2 to your computer and use it in GitHub Desktop.
Helps when doing Management Pack Tuning for SCOM
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
param( | |
[Parameter(Mandatory=$true)] | |
[string]$sourceManagementPackDisplayName, | |
[Parameter(Mandatory=$true)] | |
[string]$overrideManagementPackDisplayName, | |
[Parameter(Mandatory=$true)] | |
[ValidateSet('unitMoninitor','rule')] | |
[string]$itemType, | |
[Parameter(Mandatory=$true)] | |
[ValidateSet('True','False')] | |
[string]$itemsToBeEnabled, | |
[Parameter(Mandatory=$true)] | |
[ValidateScript({Test-Path -path $_ })] | |
[string]$inputFilePath | |
) | |
Import-Module OperationsManager | |
$comment = "Overriden by: $($env:USERNAME); On: $(Get-Date) " | |
$sourceMP = Get-SCOMManagementPack -DisplayName $sourceManagementPackDisplayName | |
$overrideMP = Get-SCOMManagementPack -DisplayName $overrideManagementPackDisplayName | |
if ($itemType -eq 'rule') { | |
$rules = $sourceMP | Get-SCOMRule | |
$rulesFromFile = Get-Content -Path $inputFilePath | |
$rules | ForEach-Object { | |
$rule = $_ | |
$rulesFromFile | ForEach-Object { | |
if ($rule.DisplayName -match $_) { | |
$targetClass = Get-ScomClass -Id $rule.Target.Id | |
$overrideName = $rule.Name + ".Override" | |
$override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackRulePropertyOverride($overrideMP,$overrideName) | |
$override.Rule = $rule | |
$override.Property = 'Enabled' | |
$override.Value = $itemsToBeEnabled | |
$override.Context = $targetClass | |
$override.Description = $comment | |
$override.DisplayName = $overrideName | |
} | |
} | |
} | |
} else { | |
$monitors = $sourceMP | Get-SCOMMonitor | Where-Object {$_.xmltag -eq "UnitMonitor"} | |
$monitorsFromFile = Get-Content -Path $inputFilePath | |
$monitors | ForEach-Object { | |
$monitor = $_ | |
$monitorsFromFile | ForEach-Object { | |
if ($monitor.DisplayName -match $_) { | |
$targetClass = Get-ScomClass -Id $monitor.Target.Id | |
$overrideName = $monitor.Name+".Override" | |
$override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($overrideMP,$overrideName) | |
$override.Monitor = $monitor | |
$override.Property = 'Enabled' | |
$override.Value = $itemsToBeEnabled | |
$override.Context = $targetClass | |
$override.Description = $comment | |
$override.DisplayName = $overrideName | |
} | |
} | |
} | |
} #end if ($itemType -eq 'rule') | |
$overrideMP.Verify() | |
$overrideMP.AcceptChanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by other sources, e.g.:
https://social.technet.microsoft.com/wiki/contents/articles/30714.scom-2012-bulk-override-creation-for-monitors-and-rules-using-powershell.aspx