1

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
}
4

1 回答 1

0

弄清楚了!

PowerShell 编辑器似乎有一个奇怪的缓存,这让它变得非常时髦......

上面的脚本实际上正在工作:)

于 2018-06-13T21:36:58.220 回答