Remove OMS MP

P2P.OMSAdministration.Tasks.DeleteMP (Task)

Removes the Targeted MP From Your ManagementGroup

Element properties:

TargetP2P.OMSAdministration.Classes.OMSManagementPack
AccessibilityInternal
CategoryMaintenance
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.PowerShellWriteAction P2P.OMSAdministration.SDKRunAs

Source Code:

<Task ID="P2P.OMSAdministration.Tasks.DeleteMP" Accessibility="Internal" Target="P2PAdmin!P2P.OMSAdministration.Classes.OMSManagementPack" Enabled="true" Timeout="300" Remotable="true">
<Category>Maintenance</Category>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction" RunAs="P2PAdmin!P2P.OMSAdministration.SDKRunAs">
<ScriptName>Remove MP.ps1</ScriptName>
<ScriptBody><Script><![CDATA[Param([String]$ManagementPackName,[String]$SolutionName)

Import-Module OperationsManager -ErrorAction SilentlyContinue
$setupKey = Get-Item -Path "HKLM:\Software\Microsoft\Microsoft Operations Manager\3.0\Setup"
$installDirectory = $setupKey.GetValue("InstallDirectory") | Split-Path
$psmPath = $installdirectory + ‘\Powershell\OperationsManager\OperationsManager.psm1’
Import-Module $psmPath -ErrorAction SilentlyContinue

New-SCOMManagementGroupConnection 'localhost' -ErrorAction Stop

#Produce IDs so we can clean our pack.
$CleanDisplayName = $SolutionName.Replace('.','')
$MPID = "P2P.OMSAdministration.SolutionControl.$CleanDisplayName"

Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5600 -Message "Deleting Management Pack $ManagementPackName for Solution $SolutionName" -Category 50

$FoundMP = $null
Try
{
#Before we go further, check for Installed Pack
$FoundMP = $MG.GetManagementPacks($MPID)
If ($FoundMP -ne $null)
{
$PackInstallDate = $FoundMP.TimeCreated.ToLocalTime().ToString()
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5650 -Message "We found the pack $MPID for $SolutionName, it was installed on $PackInstallDate. This will be deleted as part of the Process." -Category 50
Remove-SCOMManagementPack -ManagementPack $FoundMP -ErrorAction SilentlyContinue
}
Else
{
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5651 -Message "We did not find the Override pack $MPID for $SolutionName" -Category 50
}
}
Catch
{
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5651 -Message "We did not find the Override pack $MPID for $SolutionName" -Category 50
}

Get-SCOMManagementPack -Name $ManagementPackName | Remove-SCOMManagementPack

[string]$ErrorCount = $Error.Count
Write-Host "Task Completed; The error count was $ErrorCount;"
If ($Error -ne'0')
{
ForEach ($ER in $Error)
{
$ERString = $ER.tostring()
Write-Host $ERString
}
}]]></Script></ScriptBody>
<SnapIns/>
<Parameters>
<Parameter>
<Name>ManagementPackName</Name>
<Value>$Target/Property[Type="P2PAdmin!P2P.OMSAdministration.Classes.OMSManagementPack"]/MPName$</Value>
</Parameter>
<Parameter>
<Name>SolutionName</Name>
<Value>$Target/Host/Host/Property[Type="System!System.Entity"]/DisplayName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</WriteAction>
</Task>