Create Overrides 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 11 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
Enabling or Disabling Workflows in SCOM 2012 with PowerShell
Deleting Workflows in SCOM 2012 with PowerShell
Creating Groups in SCOM 2012 with PowerShell
Adding References to MPs in SCOM 2012 with PowerShell
Modifying Explicit Group Membership in SCOM 2012 with PowerShell
Get Parameters that can be Overridden in SCOM 2012 with PowerShell
Get Overrides Applied to a Workflow in SCOM 2012 using PowerShell
Get All Overrides in a SCOM 2012 Management Group using PowerShell
As of this post this script is not included as an activity in the Operations Manager Admin Integration Pack but will be in the next version.
The purpose of this script is to create an override for a specific workflow specified. Beware that not everything in this script is validated and SCOM does not validate much in the override during import. For instance, if you want to create an override for an instance of a class and you specify an invalid GUID the override will still be created and viewable in the MP XML. However, the override will not be applied correctly and will not show up if queried using the previous PowerShell scripts I wrote for getting overrides.
This script supports rules, monitors, discoveries, diagnostics, and recoveries. To get a list of workflows for each type you can run the following commands:
Get-SCOMRule | select name
Get-SCOMMonitor | select name
Get-SCOMDiscovery | select name
Get-SCOMDiagnostic | select name
Get-SCOMRecovery | select name
To get the ContextID you can run the following command:
Get-SCOMClass | select name
To get the InstanceGUID you can run the following command, specifying the same class used for the ContextID:
Get-SCOMClass –name ‘Microsoft.Windows.Computer’ | Get-SCOMClassInstance | select name, id
Syntax:
.\CreateOverride.ps1 –ManagementServer ‘om01.contoso.com’ –ManagementPackID ‘custom.example.test’ –WorkflowID ‘custom.example.test.rule.myrule’ –PropertyName ‘Enabled’ –PropertyValue ‘false’ –Enforced ‘false’ –ContextID ‘custom.example.test.group.mygoldservers’
Parameters:
Name | Description |
ManagementServer | Name of MS to connect to |
ManagementPackID | Override management pack ID. If it doesn’t exist it will be created |
WorkflowID | The id of the rule, monitor, discovery, recovery, or diagnostic that you want to override |
PropertyName | The name of the property / parameter that you want to override |
PropertyValue | The value of the property / parameter that you want to override |
Enforced | Whether you want this override to be enforced or not (true or false) |
ContextID | The class / group that you want this override applied to |
InstanceGUID | Optional: The GUID for the instance of the Context that you want this override to apply to. Only use this if you want the override to apply to a single instance of another class and make sure that the ContextID matches the same class that the instance is a member of. |
1 Param(
2 [parameter(Mandatory=$true)]
3 $ManagementServer,
4 [parameter(Mandatory=$true)]
5 $ManagementPackID,
6 [parameter(Mandatory=$true)]
7 $WorkflowID,
8 [parameter(Mandatory=$true)]
9 $PropertyName,
10 [parameter(Mandatory=$true)]
11 $PropertyValue,
12 [parameter(Mandatory=$true)]
13 $Enforced,
14 [parameter(Mandatory=$true)]
15 $ContextID,
16 $InstanceGUID
17 )
18
19 Write-Host "ManagementServer: "$ManagementServer
20 Write-Host "ManagementPackID: "$ManagementPackID
21 Write-Host "WorkflowID: "$WorkflowID
22 Write-Host "PropertyName: "$PropertyName
23 Write-Host "PropertyValue: "$PropertyValue
24 Write-Host "Enforced: "$Enforced
25 Write-Host "ContextID: "$ContextID
26 Write-Host "InstanceGUID: "$InstanceGUID
27
28 Write-Host "Version 1.0"
29
30 function GetSCOMManagementGroup
31 {
32 param($ms)
33 try
34 {
35 $mg = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ms)
36 }
37 catch
38 {
39 Write-Host "Failed to Connect to SDK, Exiting:"$ms -ForegroundColor Red
40 Write-Host $_.Exception.Message -ForegroundColor Yellow
41 exit
42 }
43 return $mg
44 }
45
46 function GetManagementPack
47 {
48 param ($mg, $mpID)
49 try
50 {
51 $mp = $mg.GetManagementPacks($mpID)[0]
52 }
53 catch
54 {
55 Write-Host "Management Pack Not Found, Exiting:"$mpID -ForegroundColor Red
56 Write-Host $_.Exception.Message -ForegroundColor Yellow
57 exit
58 }
59 return $mp
60 }
61
62 function GetManagementPackToUpdate
63 {
64 param($mg, $mpID)
65 try
66 {
67 $mp = $mg.GetManagementPacks($mpID)[0]
68 $vIncrement = $mp.Version.ToString().Split('.')
69 $vIncrement[$vIncrement.Length - 1] = ([system.int32]::Parse($vIncrement[$vIncrement.Length - 1]) + 1).ToString()
70 $mp.Version = ([string]::Join(".", $vIncrement))
71 }
72 catch
73 {
74 Write-Host "New MP:"$mpID
75 $mp = CreateManagementPack -mpID $mpID
76 $mg.ImportManagementPack($mp)
77 $mp = GetManagementPack -mg $mg -mpID $mpID
78 }
79 return $mp
80 }
81
82 function GetMPID
83 {
84 param($mg, $wfID)
85 $criteria = [string]::Format("Name = '{0}'", $wfID)
86
87 $wfTypes = ('recovery','diagnostic','recovery','monitor','rule','class', 'discovery')
88
89 foreach ($wfType in $wfTypes)
90 {
91 switch ($wfType)
92 {
93 'discovery' { try {$mpID = GetDiscoveryFromMG -mg $mg -criteria $criteria} catch {}}
94 'class' { try {$mpID = (GetClassMPFromMG -mg $mg -criteria $criteria).Name} catch {}}
95 'rule' { try {$mpID = GetRuleFromMG -mg $mg -criteria $criteria} catch {}}
96 'monitor' { try {$mpID = GetMonitorFromMG -mg $mg -criteria $criteria} catch {}}
97 'recovery' { try {$mpID = GetRecoveryFromMG -mg $mg -criteria $criteria} catch {}}
98 'diagnostic' { try {$mpID = GetDiagnosticFromMG -mg $mg -criteria $criteria} catch {}}
99 }
100 }
101
102 if ($mpID -eq $null)
103 {
104 Write-Host "Unable to Find MP, Exiting"$mpID -ForegroundColor Red
105 Write-Host $_.Exception.Message -ForegroundColor Yellow
106 exit
107 }
108
109 return $mpID
110 }
111
112 function CreateManagementPack
113 {
114 param($mpID)
115 $mpStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore
116 $mp = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($mpID, $mpID, (New-Object Version(1, 0, 0)), $mpStore)
117 return $mp
118 }
119
120 function GetReference
121 {
122 param($mg, $mp, $mpID)
123 if ($mp.Name.ToUpper() -ne $mpID.ToUpper())
124 {
125 $bFound = $false
126 foreach ($ref in $mp.References)
127 {
128 $s = ($ref.Value.ToString().Split("=")[1]).Split(",")[0]
129 if ($s.ToUpper() -eq $mpID.ToUpper()) {$bFound = $true}
130 }
131 if (!($bFound))
132 {
133 Write-Host "New Reference:"$mpID
134 $mp = CreateReference -mg $mg -mp $mp -mpID $mpID
135 }
136 }
137 return $mp
138 }
139
140 function CreateReference
141 {
142 param($mg, $mp, $mpID)
143 try
144 {
145 $newMP = $mg.GetManagementPacks($mpID)[0]
146 if (!($newMP.sealed))
147 {
148 Write-Host "MP to reference is not sealed, cannot add reference to"$mpID -ForegroundColor Red
149 Write-Host "Exiting" -ForegroundColor Red
150 Write-Host $_.Exception.Message -ForegroundColor Yellow
151 exit
152 }
153 }
154 catch
155 {
156 Write-Host "Referenced MP Not Found in Management Group, Exiting:"$mpID -ForegroundColor Red
157 Write-Host $_.Exception.Message -ForegroundColor Yellow
158 exit
159 }
160
161 $alias = $mpID.Replace(".","")
162 $reference = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackReference($newMP)
163 $mp.References.Add($alias, $reference)
164 return $mp
165 }
166
167 function GetModulesByPropertyName
168 {
169 param($workflow, $PropertyName, $overrideType)
170
171 switch ($overrideType.ToLower())
172 {
173 'discovery' { $parameters = $workflow.GetOverrideableParametersByModule() }
174 'rule' { $parameters = $workflow.GetOverrideableParametersByModule() }
175 'monitor' { $parameters = $workflow.GetOverrideableParameters() }
176 'recovery' { $parameters = $workflow.GetOverrideableParametersByModule() }
177 'diagnostic' { $parameters = $workflow.GetOverrideableParametersByModule() }
178 }
179
180 $bFound = $false
181 $modules = @{}
182 foreach ($module in $parameters.Keys)
183 {
184 foreach ($parameter in $parameters.$module)
185 {
186 if ($parameter.Name.ToUpper() -eq $propertyName.ToUpper())
187 {
188 $bFound = $true
189 $modules.Add($module.Name, $parameter.Name)
190 }
191 }
192 }
193
194 if (!($bFound))
195 {
196 Write-Host "Overrideable Parameter Not Found, Exiting:"$propertyName -ForegroundColor Red
197 exit
198 }
199 return $modules
200 }
201
202 function GetWorkflow
203 {
204 param($mp, $id, $type)
205 try
206 {
207 switch($type.ToLower())
208 {
209 'discovery' {$workflow = GetDiscovery -mp $mp -discoveryID $id}
210 'rule' {$workflow = GetRule -mp $mp -ruleID $id}
211 'monitor' {$workflow = GetMonitor -mp $mp -monitorID $id}
212 'recovery' {$workflow = GetRecovery -mp $mp -recoveryID $id}
213 'diagnostic' {$workflow = GetDiagnostic -mp $mp -diagnosticID $id}
214 }
215 }
216 catch
217 {
218 Write-Host "Workflow Not Found, Exiting:"$id -ForegroundColor Red
219 Write-Host $_.Exception.Message -ForegroundColor Yellow
220 exit
221 }
222 return $workflow
223 }
224
225 function GetWorkflowType
226 {
227 param($mg, $mpID, $wfID)
228
229 $mp = GetManagementPack -mg $mg -mpID $mpID
230 $workflow = $mp.FindManagementPackElementByName($wfID)
231 $wfType = $workflow.GetType()
232
233 switch($wfType)
234 {
235 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDiscovery' {$workflowType = 'discovery'}
236 'Microsoft.EnterpriseManagement.Configuration.ManagementPackRule' {$workflowType = 'rule'}
237 'Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonitor' {$workflowType = 'monitor'}
238 'Microsoft.EnterpriseManagement.Configuration.ManagementPackAggregateMonitor' {$workflowType = 'monitor'}
239 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDependencyMonitor' {$workflowType = 'monitor'}
240 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDiagnostic' {$workflowType = 'diagnostic'}
241 'Microsoft.EnterpriseManagement.Configuration.ManagementPackRecovery' {$workflowType = 'recovery'}
242 default
243 {
244 Write-Host "Unable to Find Workflow:"$wfID -ForegroundColor Red
245 Write-Host "Workflow Type:"$wfType -ForegroundColor Red
246 Write-Host "Exiting" -ForegroundColor Red
247 exit
248 }
249 }
250
251 return $workflowType
252 }
253
254 function GetDiscovery
255 {
256 param ($mp, $discoveryID)
257 Write-Host "Discovery:"$discoveryID
258 $discovery = $mp.GetDiscovery($discoveryID)
259 return $discovery
260 }
261
262 function GetRule
263 {
264 param ($mp, $ruleID)
265 Write-Host "Rule:"$ruleID
266 $rule = $mp.GetRule($ruleID)
267 return $rule
268 }
269
270 function GetMonitor
271 {
272 param ($mp, $monitorID)
273 Write-Host "Monitor:"$monitorID
274 $monitor = $mp.GetMonitor($monitorID)
275 return $monitor
276 }
277
278 function GetRecovery
279 {
280 param ($mp, $recoveryID)
281 Write-Host "Recovery:"$recoveryID
282 $recovery = $mp.GetRecovery($recoveryID)
283 return $recovery
284 }
285
286 function GetDiagnostic
287 {
288 param ($mp, $diagnosticID)
289 Write-Host "Diagnostic:"$diagnosticID
290 $diagnostic = $mp.GetDiagnostic($diagnosticID)
291 return $diagnostic
292 }
293
294 function GetDiscoveryFromMG
295 {
296 param($mg, $criteria)
297 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringDiscoveryCriteria($criteria)
298 $discovery = $mg.GetMonitoringDiscoveries($searchCriteria)[0]
299 $mp = $discovery.GetManagementPack()
300 return $mp.Name
301 }
302
303 function GetClassFromMG
304 {
305 param($mg, $criteria)
306 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringClassCriteria($criteria)
307 $class = $mg.GetMonitoringClasses($searchCriteria)[0]
308 return $class
309 }
310
311 function GetRuleFromMG
312 {
313 param($mg, $criteria)
314 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringRuleCriteria($criteria)
315 $rule = $mg.GetMonitoringRules($searchCriteria)[0]
316 $mp = $rule.GetManagementPack()
317 return $mp.Name
318 }
319
320 function GetMonitorFromMG
321 {
322 param($mg, $criteria)
323 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitorCriteria($criteria)
324 $monitor = $mg.GetMonitors($searchCriteria)[0]
325 $mp = $monitor.GetManagementPack()
326 return $mp.Name
327 }
328
329 function GetDiagnosticFromMG
330 {
331 param($mg, $criteria)
332 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringDiagnosticCriteria($criteria)
333 $diagnostic = $mg.GetMonitoringDiagnostics($searchCriteria)[0]
334 $mp = $diagnostic.GetManagementPack()
335 return $mp.Name
336 }
337
338 function GetRecoveryFromMG
339 {
340 param($mg, $criteria)
341 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringRecoveryCriteria($criteria)
342 $recovery = $mg.GetMonitoringRecoveries($searchCriteria)[0]
343 $mp = $recovery.GetManagementPack()
344 return $mp.Name
345 }
346
347 function GetClassMPFromMG
348 {
349 param($mg, $criteria)
350 $searchCriteria = new-object Microsoft.EnterpriseManagement.Configuration.MonitoringClassCriteria($criteria)
351 $class = $mg.GetMonitoringClasses($searchCriteria)[0]
352 $mp = $class.GetManagementPack()
353 return $mp
354 }
355
356 function GetOverrideStatus
357 {
358 param($override)
359 if ($override)
360 {
361 $status = 'PendingUpdate'
362 }
363 else
364 {
365 $status = 'PendingAdd'
366 }
367 return $status
368 }
369
370 function GetFormattedOverrideType
371 {
372 param($overrideType)
373
374 switch ($overrideType.ToLower())
375 {
376 'discovery' {$type = 'Discovery'}
377 'rule' {$type = 'Rule'}
378 'monitor' {$type = 'Monitor'}
379 'recovery' {$type = 'Recovery'}
380 'diagnostic' {$type = 'Diagnostic'}
381 }
382 return $type
383 }
384
385 function GetOverride
386 {
387 param($mp, $overrideID)
388 try
389 {
390 $override = $mp.GetOverride($overrideID)
391 Write-Host "Modify Existing Override:"$overrideID
392 }
393 catch
394 {
395 Write-Host "New Override:"$overrideID
396 $override = $null
397 }
398 return $override
399 }
400
401 function IsPropertyOverride
402 {
403 param($overrideType, $propertyName)
404 switch ($overrideType.ToLower())
405 {
406 'discovery' {$bProperty = (([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName) -ne $null)}
407 'rule' {$bProperty = (([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName) -ne $null)}
408 'monitor' {$bProperty = (([Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorProperty]::$propertyName) -ne $null)}
409 'recovery' {$bProperty = (([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName) -ne $null)}
410 'diagnostic' {$bProperty = (([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName) -ne $null)}
411 }
412 return $bProperty
413 }
414
415 function CreatePropertyOverride
416 {
417 param($mp, $override, $overrideID, $propertyName)
418
419 if (!($override))
420 {
421 switch ($overrideType.ToLower())
422 {
423 'discovery'
424 {
425 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackDiscoveryPropertyOverride($mp, $overrideID)
426 $override.Property = [Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName
427 }
428 'rule'
429 {
430 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackRulePropertyOverride($mp, $overrideID)
431 $override.Property = [Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName
432 }
433 'monitor'
434 {
435 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($mp, $overrideID)
436 $override.Property = [Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorProperty]::$propertyName
437 }
438 'recovery'
439 {
440 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackRecoveryPropertyOverride($mp, $overrideID)
441 $override.Property = [Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName
442 }
443 'diagnostic'
444 {
445 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackDiagnosticPropertyOverride($mp, $overrideID)
446 $override.Property = [Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty]::$propertyName
447 }
448
449 }
450 }
451 return $override
452 }
453
454 function CreateConfigurationOverride
455 {
456 param($mp, $overrideID, $propertyName, $o)
457
458 switch ($overrideType.ToLower())
459 {
460 'discovery'
461 {
462 Write-Host "Creating Configuration Override for Module:"$o.Key
463 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackDiscoveryConfigurationOverride($mp, $overrideID)
464 $override.Parameter = $o.Value
465 $override.Module = $o.Key
466 }
467 'rule'
468 {
469 Write-Host "Creating Configuration Override for Module:"$o.Key
470 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackRuleConfigurationOverride($mp, $overrideID)
471 $override.Parameter = $o.Value
472 $override.Module = $o.Key
473 }
474 'monitor'
475 {
476 Write-Host "Creating Configuration Override for Module:"$o.Key
477 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorConfigurationOverride($mp, $overrideID)
478 $override.Parameter = $o.Value
479 $override.Module = $o.Key
480 }
481 'recovery'
482 {
483 Write-Host "Creating Configuration Override for Module:"$o.Key
484 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackRecoveryConfigurationOverride($mp, $overrideID)
485 $override.Parameter = $o.Value
486 $override.Module = $o.Key
487 }
488 'diagnostic'
489 {
490 Write-Host "Creating Configuration Override for Module:"$o.Key
491 $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackDiagnosticConfigurationOverride($mp, $overrideID)
492 $override.Parameter = $o.Value
493 $override.Module = $o.Key
494 }
495 }
496 return $override
497 }
498
499 function CreateOverride
500 {
501 param($mg, $mp, $overrideType, $workflowID, $workflowMPID, $contextID, $propertyName, $propertyValue, $enforced, $instanceGUID)
502
503 $workflowMP = GetManagementPack -mg $mg -mpID $workflowMPID
504 $workflow = GetWorkflow -mp $workflowMP -id $WorkflowID -type $overrideType
505 if ($instanceGUID -ne $null)
506 { $overrideID = $mp.Name + ".Override.For" + $overrideType + $workflowID.Replace(".","") + ".AndPropertyOf" + $propertyName + ".AppliedToContextOf" + $contextID.Replace(".","") + ".AndInstanceOf" + $instanceGUID.Replace("-", "") }
507 else { $overrideID = $mp.Name + ".Override.For" + $overrideType + $workflowID.Replace(".","") + ".AndPropertyOf" + $propertyName + ".AppliedToContextOf" + $contextID.Replace(".","") }
508
509 if ($overrideID.Length -gt 256)
510 {
511 $overrideID = $mp.Name + ".Override.For" + $overrideType + $workflowID.Replace(".","") + ([guid]::NewGuid().ToString()).Replace("-","")
512 if ($overrideID.Length -gt 256)
513 {
514 $overrideID = $mp.Name + ".Override." + ([guid]::NewGuid().ToString()).Replace("-","")
515 }
516 }
517
518 $override = GetOverride -mp $mp -overrideID $overrideID
519 $context = GetClassFromMG -mg $mg -criteria ([string]::Format("Name = '{0}'", $contextID))
520 $status = GetOverrideStatus -override $override
521 $type = GetFormattedOverrideType -overrideType $overrideType
522 $bProperty = IsPropertyOverride -overrideType $overrideType -propertyName $propertyName
523
524 if ($bProperty)
525 {
526 $override = CreatePropertyOverride -mp $mp -override $override -overrideID $overrideID -propertyName $propertyName
527 $override.$Type = $workflow
528 $override.Value = $propertyValue
529 $override.Context = $context
530 if ($instanceGUID -ne $null) { $override.ContextInstance = $instanceGUID }
531 $override.Enforced = $enforced
532 $override.Status = $status
533 }
534 else
535 {
536 if (!($override))
537 {
538 $modules = GetModulesByPropertyName -workflow $workflow -PropertyName $propertyName -overrideType $overrideType
539 foreach ($o in $modules.GetEnumerator())
540 {
541 $override = CreateConfigurationOverride -mp $mp -overrideID $overrideID -propertyName $propertyName -o $o
542 $override.$Type = $workflow
543 $override.Value = $propertyValue
544 $override.Context = $context
545 if ($instanceGUID -ne $null) { $override.ContextInstance = $instanceGUID }
546 $override.Enforced = $enforced
547 $override.Status = $status
548 }
549 }
550 else
551 {
552 $override.$Type = $workflow
553 $override.Value = $propertyValue
554 $override.Context = $context
555 if ($instanceGUID -ne $null) { $override.ContextInstance = $instanceGUID }
556 $override.Enforced = $enforced
557 $override.Status = $status
558 }
559 }
560
561 return $mp
562 }
563
564 #Adding SCOM Module
565 try { Import-Module OperationsManager } catch
566 {
567 Write-Host "SCOM Module Not Found, Exiting" -ForegroundColor Red
568 Write-Host $_.Exception.Message -ForegroundColor Yellow
569 exit
570 }
571
572 #Connect to SCOM Management Group
573 $MG = GetSCOMManagementGroup -ms $ManagementServer
574
575 #Get Workflow Management Pack ID from Management Group
576 $WorkflowMPID = GetMPID -mg $MG -wfID $WorkflowID
577
578 #Get Workflow Type
579 $OverrideType = GetWorkflowType -mg $MG -mpID $WorkflowMPID -wfID $WorkflowID
580
581 #Get Context Management Pack ID from Management Group
582 $ContextMPID = GetMPID -mg $MG -wfID $ContextID -wfType 'class'
583
584 #Get Override MP and Increment Version
585 $MP = GetManagementPackToUpdate -mg $MG -mpID $ManagementPackID
586
587 #Validate that the Workflow MP is Referenced in the Override MP, or that we are using the same MP
588 $MP = GetReference -mg $MG -mp $MP -mpID $WorkflowMPID
589
590 #Validate that the Context MP is Referenced in the Override MP, or that we are using the same MP
591 $MP = GetReference -mg $MG -mp $MP -mpID $ContextMPID
592
593 #Create Override
594 $MP = CreateOverride -mg $MG -mp $MP -overrideType $OverrideType -workflowMPID $WorkflowMPID -workflowID $WorkflowID -contextID $ContextID -propertyName $PropertyName -propertyValue $PropertyValue -enforced $Enforced -instanceGUID $InstanceGUID
595
596 Write-Host "Write Changes to Management Pack"
597 try { $MP.AcceptChanges() }
598 catch
599 {
600 $MP.RejectChanges()
601 Write-Host "Failed to Update MP, Exiting:"$ms -ForegroundColor Red
602 Write-Host $_.Exception.Message -ForegroundColor Yellow
603 exit
604 }
605
606 Write-Host "Script Completed"