just curious - I have a solution, but I am trying to understand what is wrong:
this first simple script works (has a fixed GUID)
$servername = myServer
$addition = "andre"
######################################################################
$mp1 = Get-SCOMManagementPack -DisplayName 'My_MP'
$o = $mp1.GetOverrides()
foreach ($ov in $o)
{
if ($ov.parameter -eq "Arguments" -and $ov.contextinstance -eq "04e18d3e-5a73-70e2-32f4-d5333151d712")
{
$ov.Value = $ov.value + "," + $addition
$ov.status = "PendingUpdate"
$ov
$mp1.verify()
$mp1.Acceptchanges()
break
}
}
now, because I am not sure in which MP the override might be stored, I load all overrides in the management group, step thru them, and I get the windows computer object, so I have the GUID (instead of hardcode it like above)
$servername = myServer
$addition = "andre"
$MG = Get-SCOMManagementGroup -ComputerName $RMS
#get all existing overrides
$criteria = ([string]::Format("Name like '%'"))
$searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringOverrideCriteria($criteria)$overrides = $MG.GetMonitoringOverrides($searchCriteria)
#now lets first find the windows computer instance for which we want to create/update the override.
$cl = Get-SCOMClass -DisplayName "windows computer"
$ci = Get-SCOMClassInstance -Class $cl | where { $_.DisplayName -eq $servername }
#let's step thru all existing overrides
foreach ($ov in $overrides)
{
if ($ov.ContextInstance -eq $ci.id.guid
-and $ov.parameter -eq "Arguments")
{
#if we get here, it means we have found an existing override
# for the right computer instance and the right parameter value
#lets first get the mp in which the override is stored
$mon = Get-SCOMMonitor -Id $ov.Monitor.ToString().split("=")[1]
if ($mon.DisplayName -eq "Accounts")
{
#right monitor too, lets update the MP.
$mp_ov_name = $ov.GetManagementPack().Name
$mp1 = Get-SCOMManagementPack -Name $mp_ov_name
$OverrideValue = $ov.value
if (($OverrideValue.split(",")) -notcontains $addition)
{
$ov.Value = $ov.value + "," + $addition
$ov.status = "PendingUpdate"
$mp1.Verify()
$mp1.AcceptChanges()
break
}
Else
{
write-host "Addition is already in override"
}
}
}
}
looks good I thought, when I step thru it, everything seems fine, the override is OK, it is update etc, Acceptchanges takes a while, but, the override is not updated....
the solution is:
$servername = myServer
$addition = "andre"
######################################################################
$MG = Get-SCOMManagementGroup -ComputerName $RMS
#get all existing overrides
$criteria = ([string]::Format("Name like '%'"))
$searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringOverrideCriteria($criteria)$overrides = $MG.GetMonitoringOverrides($searchCriteria)
#now lets first find the windows computer instance for which we want to create/update the override.
$cl = Get-SCOMClass -DisplayName "windows computer"
$ci = Get-SCOMClassInstance -Class $cl | where { $_.DisplayName -eq $servername }
#let's step thru all existing overrides
foreach ($oo in $overrides)
{
if ($oo.ContextInstance -eq $ci.id.guid -and $oo.parameter -eq "Arguments")
{
# if we get here, it means we have found an existing override for the right computer instance and the right parameter value
$mon = Get-SCOMMonitor -Id $oo.Monitor.ToString().split("=")[1]
if ($mon.DisplayName -eq "_BHI Monitor Unauthorized Accounts")
{
#lets first get the mp in which the override is stored
$mp_ov_name = $oo.GetManagementPack().Name
$mp1 = Get-SCOMManagementPack -Name $mp_ov_name
$o1 = $mp1.GetOverrides()
foreach ($ov in $o1)
{
if ($ov.parameter -eq "Arguments" -and $ov.contextinstance -eq $ci.id.guid)
{
$OverrideValue = $ov.value
if (($OverrideValue.split(",")) -notcontains $addition)
{
$ov.Value = $ov.value + "," + $addition
$ov.status = "PendingUpdate"
$ov
$mp1.verify()
$mp1.Acceptchanges()
break
}
Else
{
write-host "Addition is already in override"
}
}
}
}
}
}
The only explanation I can think of is that the override that I selected out of the $overrides (collection of ALL Overrides in SCOM) does not have a direct relationship with the $mp1 in the 2nd example. but... when I do a $oo.GetManagementPack(), it shows
me the reference to the MP where it is stored in.....
so in the last (3rd) example, I determine the mp, load the mp, and "again" load all the overrides stored in that single mp and "again" find the override that I want to update. and now when I do $mp1.acceptchanges(), it does
work OK....
but, it puzzles me, I have compared the override details, and they are identical, all values that I see are the same....
when debugging the scripts: $ov (the override) in script1, 2 and 3 seems identical I cannot spot a difference