пятница, 26 июня 2015 г.

Remove specific data from XML with PowerShell. Records from SCOM Default User MP for example

Hi,

Just to save for myself too. I was playing with XML support in PowerShell and was able to use the following to delete part of the XML. This is very useful, especialy for dealing with Operations Manager Default User Management Pack. You can select data for a specific Management Pack and delete it, so that the desired Management pack can be removed without deleting the Default User MP.
$xml = [xml](Get-Content ".\Microsoft.SystemCenter.OperationsManager.DefaultUser.xml")
$xml.ManagementPack.Monitoring.Overrides.MonitorPropertyOverride | ? {$_.Monitor -like "*Exchange*" -or $_.Context -like "*Exchange*"} | % {$_.ParentNode.RemoveChild($_)}
You can also export these contents before deleting. Like that
$xml.ManagementPack.Monitoring.Overrides.MonitorPropertyOverride | ? {$_.Monitor -like "*Exchange*" -or $_.Context -like "*Exchange*"} | % {$_.OuterXML} | Out-File .\MPO.xml

 To save the update MP, use Save method:
$xml.Save("FullPath")

Комментариев нет:

Отправить комментарий