Bulk Update of Overrides
I have a need to update the Description field in hundreds of overrides. I have tried doing this via PowerShell, but have failed so far. Has anyone been able to accomplish something like this?
September 15th, 2009 2:26pm
What have you tried in Powershell? Can you paste in your script, perhaps we can help debug.Thanks,-Lincoln
Free Windows Admin Tool Kit Click here and download it now
September 15th, 2009 5:21pm
$mp = Get-ManagementPack | Where {$_.Name -eq 'Custom.SQL.MP'}
$mpo = Get-Override -ManagementPack $mp | Where {$_.Description -eq $null -and $_.Id -eq '43bc1c61-5fe7-12c9-3355-f2ac38f9ad7c'}
$mpo.Description = 'DESCRIPTION'
$mpo.AcceptChanges();
This produces the following error: Method invocation failed because [Microsoft.EnterpriseManagement.Configuration.MonitoringRulePropertyOverride] doesn't contain a method named 'AcceptChanges'. At C:\test.ps1:16 char:19 + $mpo.AcceptChanges <<<< (); + CategoryInfo : InvalidOperation: (AcceptChanges:String) [], Runtime Exception + FullyQualifiedErrorId : MethodNotFound I have also tried it like this:
$mp = Get-ManagementPack | Where {$_.Name -eq 'Custom.SQL.MP'} | Get-Override | Where {$_.Description -eq $null -and $_.Id -eq '43bc1c61-5fe7-12c9-3355-f2ac38f9ad7c'}
$mp.Description = 'DESCRIPTION'
$mp.AcceptChanges();
This produces the following error: Method invocation failed because [Microsoft.EnterpriseManagement.Configuration.MonitoringRulePropertyOverride] doesn't contain a method named 'AcceptChanges'. At C:\test.ps1:16 char:18 + $mp.AcceptChanges <<<< (); + CategoryInfo : InvalidOperation: (AcceptChanges:String) [], Runtime Exception + FullyQualifiedErrorId : MethodNotFound I have also tried:
$mp = Get-ManagementPack | Where {$_.Name -eq 'Custom.SQL.MP'}
$mpo = Get-Override -ManagementPack $mp | Where {$_.Description -eq $null -and $_.Id -eq '43bc1c61-5fe7-12c9-3355-f2ac38f9ad7c'}
$mpo.Description = 'DESCRIPTION'
$mp.AcceptChanges();
This doesn't produce any errors, but it doesn't update the Description field either. Both examples above are just getting the one override, I have some looping code already to get all the overrides I want to update, just haven't been able to get the one to update yet.
September 16th, 2009 7:43am
The last approach is correct, but missing one step. Try this:$mp = Get-ManagementPack | Where {$_.Name -eq 'Custom.SQL.MP'}$mpo = Get-Override -ManagementPack $mp | Where {$_.Description -eq $null -and $_.Id -eq '43bc1c61-5fe7-12c9-3355-f2ac38f9ad7c'}$mpo.Description = 'DESCRIPTION'$mpo.Status = "PendingUpdate"$mp.AcceptChanges();Thanks,-Lincoln
Free Windows Admin Tool Kit Click here and download it now
September 18th, 2009 2:28pm
Thanks for pointing that out. I now get the following error: Exception calling "AcceptChanges" with "0" argument(s): "Failed to validate item [ID=ENU]." At line:1 char:18 + $mp.AcceptChanges <<<< (); + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
September 30th, 2009 3:21pm
Do you have the overrides already created? Just export the MP(s) and do a find and replace with notepad++.
If that doesn't work Marco created asimilarscript that might help you.
$exportDir="c:\some_dir"$newFrequency="240""Exporting unsealed MPs"# Export all unsealed MPs.get-managementpack|where{!($_.sealed)}|export-managementpack -path $exportDir"Looping through each exported MP"# Loop through all the exported MPs.foreach($mp in dir $exportDir){# Set some variables $changed=$false # Used if the MPs XML was changed. $i=0 # Used to count the number of changes in the XML. "Loading MP: "+$mp.name.replace(".xml",$null) $xml=[xml](get-content $mp.fullname)# Xpath query to get the nodes where the frequency value is stored. "Checking frequency values"# Old $xml.selectnodes("/ManagementPack/Monitoring/Discoveries/Discovery/DataSource/Frequency")|foreach{# New $xml.selectnodes("/ManagementPack/Monitoring/Discoveries/Discovery")|where{
($_.ID -like "UINameSpace*WindowsService.DiscoveryRule") -or ($_.ID -like "ServiceStateProbePage*DiscoverRule")
}|foreach{ $_.selectnodes("DataSource/Frequency") }|foreach{ if($_.get_InnerText() -eq 60){$_.set_InnerText($newFrequency);$changed=$true;$i++} } if($changed){ " XML for MP has changed: There are "+$i+" change/changes" " Saving the new XML to a file" $xml.save($mp.fullname) " Loading the new XML file" install-managementpack $mp.fullname }}"Done"
Tim McFadden
http://www.scom2k7.com
Free Windows Admin Tool Kit Click here and download it now
September 30th, 2009 4:38pm
find and replace won't work because the entry for the Description isn't there to search. These are overrides created with Boris's overridecreator.exe http://blogs.msdn.com/boris_yanushpolsky/archive/2007/08/04/disabling-enabling-multiple-rules-monitors-discoveries-at-once.aspx I left a comment on the above blog post, but it's never been approved and doesn't show up. The ideal solution would be to modify overridecreator.exe and add the option to enter a Description when creating the overrides. What I was trying to do via PowerShell, was after I create the overrides with overridecreator then I would run a script that looks for all overrides last modified in the last 10 minutes or so that do not have a value for Description and add the Description I specify. It's really frustrating that something like this isn't possible, or at least I haven't been able to figure it out yet. Creating hundreds of overrides via the GUI is very tedious.
October 1st, 2009 8:37am
Are you talking about alert description? That is not an overridable parameter. What mp are you trying to fix up?
Free Windows Admin Tool Kit Click here and download it now
October 1st, 2009 5:01pm
Ok, I investigated this and found out the problem. Here's what you need:$mp = Get-ManagementPack | Where {$_.Name -eq 'Custom.SQL.MP'}$mpo = Get-Override -ManagementPack $mp | Where {$_.Description -eq $null -and $_.Id -eq '43bc1c61-5fe7-12c9-3355-f2ac38f9ad7c'}$mpo.Description = 'DESCRIPTION'$mpo.DisplayName = "qwerty" # set DisplayName to anything you want$mpo.Status = "PendingUpdate"$mp.AcceptChanges();This seems like a bizarre fix, and I have filed a bug for the confusing experience here. In a nutshell, you can't set any of the "Display" strings on an MP element unless the "DisplayName" property is set first (or at the same time). Since your overrides have a blank DisplayName, it was complaining that you were trying to set the Description field by itself. By giving your overrides a DisplayName (any string will do) you are then allowed to give them Descriptions. Hope that gets you moving...Thanks,-Lincoln
October 1st, 2009 6:11pm
Thanks, that fixed it.
Free Windows Admin Tool Kit Click here and download it now
October 2nd, 2009 12:01am
In 2007, Yakub Oleksy in
his blog about MP authoring and the SDK specifically mentioned both the 'PendingUpdate' status and the need to AcceptChanges().
August 15th, 2012 8:05pm