Skip to content

Instantly share code, notes, and snippets.

@Juanito99
Created June 13, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juanito99/ae7f1ec364ec55bfeb316c3e029d20b2 to your computer and use it in GitHub Desktop.
Save Juanito99/ae7f1ec364ec55bfeb316c3e029d20b2 to your computer and use it in GitHub Desktop.
Helps when doing Management Pack Tuning for SCOM
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