powershell - SCOM Create ClassInstance Override via PowerShell
问题描述
At this point I'm getting pretty desperate for help.. Because of certain configuration issues (I will not be going into details about this... I had nothing to do with it, I'm just dealing with the issues having to use SCOM afterwards...) I am in desperate need to script overrides in SCOM, and I've hit a wall.
In very very short: I need to set an override on a disk (or single object instance).
After finally figuring out that there is a ContextInstance param where I need to specify the object instance reference, I thought things would get easier.. but now I keep getting the error:
Exception calling "AcceptChanges" with "0" argument(s): "Object reference not >set to an instance of an object."
Shouldn't the object reference be set when I specify the GUID in the ContextInstance? I've pasted the code below, so you have a better view of what I'm doing / trying to do. I apologize for the bad looking code, but I'm in a hurry, and I'm just testing.
ANY input on how to get this working is highly (very highly!) appreciated!
break
$mps = Get-SCOMManagementPack | Out-GridView -PassThru
$overrideMp = Get-SCOMManagementPack | Out-GridView -PassThru
$monitor = $mps|Get-SCOMMonitor | Out-GridView -PassThru -Title "Get Monitor
from $($mps.DisplayName)"
$overridableParameters = $monitor.GetOverrideableParameters()
$overridePropertyName = 'IntervalSeconds'
$overridePropertyValue = "500"
$class = Get-SCOMClass -Id $monitor.Target.Id
$disk = Get-SCOMClassInstance -Id "083e63d0-5937-6da7-e052-0dac0e712be4" |
Select *
$diskInstance = New-Object
Microsoft.EnterpriseManagement.Configuration.ManagementPack
if($monitor.$overridePropertyName -ne $overridePropertyValue) {
$overridname = $Monitor.name+".Override"
$override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorConfigurationOverride($overrideMp,$overridname)
$override.Monitor = $Monitor
$override.Parameter = $overridePropertyName
$override.Value = $overridePropertyValue
$override.Context = Get-SCOMClass $disk.MonitoringClassIds
$override.ContextInstance = $disk.Id
$override.DisplayName = $overridname
$override.Description = "Test OVR"
} Else {
Write-Output "Override contains same value as current Monitor"
}
Try {
$overrideMP.AcceptChanges()
} Catch {
"Catch"
Write-Output $_.Exception.Message
}
解决方案
弄清楚了!
PowerShell 编辑器似乎有一个奇怪的缓存,这让它变得非常时髦......
上面的脚本实际上正在工作:)
推荐阅读
- android - 改造中的表单数据请求失败
- java - Android Studio 中的图像资源变得奇怪
- javascript - 正在显示 HTML 图像文本而不是图像
- apache-spark - 在 spark-submit 上获取多条消息“寻求最早并重置分区主题分区的偏移量”
- html - 如何修复文本不对齐?
- html - 将查看区域之间的图像与左右文本对齐
- python - 为什么使用函数 scipy.stats.median_absolute_deviation 计算的 MAD 与我所做的函数不同?
- r - 如何使用 Reticulate 在 R shiny App 中导入 Python 函数以供下载 App
- amazon-dynamodb - 在 DynamoDB 中创建 Web 流量日志的最佳方法是什么?
- javascript - 在 Next JS 中更新路由器查询而不触发页面更改事件