Enabling or Disabling Workflows in SCOM 2012 with PowerShell
This is a continuation of a Data Center Automation series of posts that I have been working on with Anders Bengtsson. Here are the first three posts in this series:
Creating Management Packs in SCOM 2012 with PowerShell
Creating Performance Collection Rules in SCOM 2012 with PowerShell
Creating Event Based Alerting Rules in SCOM 2012 with PowerShell
This script is also included as an activity in the Operations Manager Admin Integration Pack.
Syntax:
.\EnableOrDisable –ManagementServer ‘om01.contoso.com’ –ManagementPackID ‘custom.example.test’ –MPObjectID ‘custom.example.test.rule.test1’ –Enabled false
Parameters:
Name | Description |
ManagementServer | Name of MS to connect to |
ManagementPackID | ID of the MP you want to modify |
MPObjectID | Rule, Monitor, Discovery, or Task that you want to disable or enable (assumes unsealed as it doesn’t create an override) |
Enabled | false if you want it disabled, true if you want it enabled |
1 Param(
2 [parameter(Mandatory=$true)]
3 $ManagementServer,
4 [parameter(Mandatory=$true)]
5 $ManagementPackID,
6 [parameter(Mandatory=$true)]
7 $MPObjectID,
8 [parameter(Mandatory=$true)]
9 $Enabled
10 )
11
12 Write-Host "ManagementServer: "$ManagementServer
13 Write-Host "ManagementPackID: "$ManagementPackID
14 Write-Host "MPObjectID: "$MPObjectID
15 Write-Host "Enabled: "$Enabled
16
17 Write-Host "Adding SCOM Snap-in"
18 Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
19
20 Write-Host "Connecting to SCOM Management Group"
21 $ManagementServer = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ManagementServer)
22
23 Write-Host "Getting MP Information and Incrementing Version"
24 try
25 {
26 $MP = $ManagementServer.GetManagementPacks($ManagementPackID)[0]
27 $VIncrement = $MP.Version.ToString().Split('.')
28 $VIncrement[$VIncrement.Length - 1] = ([system.int32]::Parse($VIncrement[$VIncrement.Length - 1]) + 1).ToString()
29 $MP.Version = ([string]::Join(".", $VIncrement))
30 }
31 catch
32 {
33 Write-Host "MP Not Found, Exiting"
34 exit
35 }
36
37 Write-Host "Getting MP Object"
38 $MPObject = $MP.FindManagementPackElementByName($MPObjectID)
39
40 Write-Host "Setting Enabled Property"
41 [bool]$Enabled = [System.Convert]::ToBoolean($Enabled)
42 If (!($Enabled)){$MPObject.Enabled = [Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitoringLevel]::false}
43 Else {$MPObject.Enabled = [Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitoringLevel]::true}
44
45 Write-Host "Setting MP Status"
46 $MPObject.Status = [Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus]::PendingUpdate
47
48 Write-Host "Writing Changes via SDK"
49 $MP.AcceptChanges()
50
51 Write-Host "Script Completed"