我想创建PowerShell脚本来覆盖我的监视器和规则的某些参数。我使用下面的代码,但我有一些错误。我想覆盖我的overidable参数未启用或其他。我怎么能这样做?
$mps = Get-SCOMManagementPack | ? {$_.Name -like "test"}
$overrideMp = Get-SCOMManagementPack -DisplayName "Overrides"
$overridename = "testmonitor.Overrides"
$monitor = 'testmonitor'
$override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($overrideMp,$overridename)
$override.Monitor = $monitor
$override.Property = 'WarningThreshold'
$override.Value = 80
$override.DisplayName = "Overrides"
$overrideMp.Verify()
$overrideMp.AcceptChanges()
错误:
error1: Exception setting "Property": "Cannot convert value "WarningThreshold" to type "Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorProperty". Error: "Unable to match the identifier name WarningThreshold to a valid enumerator name. Specify one of the following enumerator names and try again: Enabled, TraceEnabled, Algorithm, AlgorithmPercentage, DefaultState, GenerateAlert, AutoResolve, AlertPriority, AlertOnState, AlertSeverity, AlertMessage, AlertParameter1, AlertParameter2, AlertParameter3, AlertParameter4, AlertParameter5, AlertParameter6, AlertParameter7, AlertParameter8, AlertParameter9, AlertParameter10, MemberInMaintenance, MemberUnavailable, IgnoreMemberInMaintenance, IgnoreMemberUnavailable"" At line:1 char:2 + $override.Property = $parametername + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting
error2 : Exception calling "AcceptChanges" with "0" argument(s): "Database error. MPInfra_p_ManagementPackInstall failed with exception: Failed to validate item: testrule1" At line:193 char:1 + $MP.AcceptChanges() + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ManagementPackException
答案 0 :(得分:0)
错误消息对我来说非常清楚。 ManagementPackMonitorProperty
枚举中没有属性WarningThreshold
。我对SCOM没有太多经验,但您可能需要为属性AlertOnState
具有值Warning
的监视器覆盖属性AlertSeverity
。
尝试以下内容:
$mps | Get-SCOMMonitor | Where-Object {
# (other selection criteria) -and
$_.AlertSettings.AlertSeverity -eq 'Warning'
} | ForEach-Object {
$ctx = Get-SCOMClass -Id $_.Target.Id
# ...
$override = New-Object ...
$override.Monitor = $_
$override.Property = 'AlertOnState'
$override.Value = 80
$override.Context = $ctx
# ...
}
从here采用的代码(可能与您找到它的地方相同)。但不确定这是否有效。就像我说的,我对SCOM的经验很少,而且我没有可用于测试的SCOM服务器。
答案 1 :(得分:0)
我明天会在办公室尝试调试它。
BTW,有一个名为MPTuner的第三方覆盖管理工具:http://mpwiki.viacode.com/default.aspx?g=mptuner 它是免费的,所以你应该尝试。罗马。
答案 2 :(得分:0)
这很令人困惑,但每种工作流程类型有两种不同类型的覆盖。对于监视器,有:
MonitorPropertyOverride
MonitorConfigurationOverride
您使用的是第一个,例如,仅适用于标准参数,例如Enabled。对于任何自定义参数,请使用“配置覆盖”。