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 eight 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
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.
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
Syntax:
.\GetOveriddableParameters.ps1 –ManagementServer ‘om01.contoso.com’ –WorkflowID ‘custom.example.test.rule.myrule’
Parameters:
Name | Description |
ManagementServer | Name of MS to connect to |
WorkflowID | ID of the rule, monitor, discovery, diagnostic, or recovery that you want the available overrides for. You can use the output of the PowerShell cmdlets I listed above. This script supports only a single workflow name at this time. |
1Param( 2 [parameter(Mandatory=$true)] 3$ManagementServer, 4 [parameter(Mandatory=$true)] 5$WorkflowID 6 ) 7 8Write-Host "Version 1.0" 9Write-Host "ManagementServer:"$ManagementServer 10Write-Host "WorkflowID:"$WorkflowID 11 12function GetSCOMManagementGroup 13{ 14param($ms) 15 try 16 { 17$mg= New-Object Microsoft.EnterpriseManagement.ManagementGroup($ms) 18 } 19 catch 20 { 21 Write-Host "Failed to Connect to SDK, Exiting:"$ms-ForegroundColor Red 22 Write-Host $_.Exception.Message -ForegroundColor Yellow 23 exit 24 } 25return$mg 26} 27 28function GetManagementPack 29{ 30param ($mg, $mpID) 31 try 32 { 33$mp=$mg.GetManagementPacks($mpID)[0] 34 } 35 catch 36 { 37 Write-Host "Management Pack Not Found, Exiting:"$mpID-ForegroundColor Red 38 Write-Host $_.Exception.Message -ForegroundColor Yellow 39 exit 40 } 41return$mp 42} 43 44function GetMPID 45{ 46param($mg, $wfID) 47$criteria= [string]::Format("Name = '{0}'", $wfID) 48 49$wfTypes= ('recovery','diagnostic','recovery','monitor','rule','class', 'discovery') 50 51foreach ($wfTypein$wfTypes) 52 { 53switch ($wfType) 54 { 55 'discovery' { try {$mpID= GetDiscoveryFromMG -mg $mg-criteria $criteria} catch {}} 56 'class' { try {$mpID= (GetClassMPFromMG -mg $mg-criteria $criteria).Name} catch {}} 57 'rule' { try {$mpID= GetRuleFromMG -mg $mg-criteria $criteria} catch {}} 58 'monitor' { try {$mpID= GetMonitorFromMG -mg $mg-criteria $criteria} catch {}} 59 'recovery' { try {$mpID= GetRecoveryFromMG -mg $mg-criteria $criteria} catch {}} 60 'diagnostic' { try {$mpID= GetDiagnosticFromMG -mg $mg-criteria $criteria} catch {}} 61 } 62 } 63 64if ($mpID-eq$null) 65 { 66 Write-Host "Unable to Find MP, Exiting"$mpID-ForegroundColor Red 67 Write-Host $_.Exception.Message -ForegroundColor Yellow 68 exit 69 } 70 71return$mpID 72} 73 74function GetWorkflowType 75{ 76param($mg, $mpID, $wfID) 77 78$mp= GetManagementPack -mg $mg-mpID $mpID 79$workflow=$mp.FindManagementPackElementByName($wfID) 80$wfType=$workflow.GetType() 81 82switch($wfType) 83 { 84 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDiscovery' {$workflowType= 'discovery'} 85 'Microsoft.EnterpriseManagement.Configuration.ManagementPackRule' {$workflowType= 'rule'} 86 'Microsoft.EnterpriseManagement.Configuration.ManagementPackUnitMonitor' {$workflowType= 'monitor'} 87 'Microsoft.EnterpriseManagement.Configuration.ManagementPackAggregateMonitor' {$workflowType= 'monitor'} 88 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDependencyMonitor' {$workflowType= 'monitor'} 89 'Microsoft.EnterpriseManagement.Configuration.ManagementPackDiagnostic' {$workflowType= 'diagnostic'} 90 'Microsoft.EnterpriseManagement.Configuration.ManagementPackRecovery' {$workflowType= 'recovery'} 91default 92 { 93 Write-Host "Unable to Find Workflow:"$wfID-ForegroundColor Red 94 Write-Host "Workflow Type:"$wfType-ForegroundColor Red 95 Write-Host "Exiting"-ForegroundColor Red 96 exit 97 } 98 } 99100return$workflowType101}102103function GetDiscovery104{105param ($mp, $discoveryID)106$discovery=$mp.GetDiscovery($discoveryID)107return$discovery108}109110function GetRule111{112param ($mp, $ruleID)113$rule=$mp.GetRule($ruleID)114return$rule115}116117function GetMonitor118{119param ($mp, $monitorID)120$monitor=$mp.GetMonitor($monitorID)121return$monitor122}123124function GetRecovery125{126param ($mp, $recoveryID)127$recovery=$mp.GetRecovery($recoveryID)128return$recovery129}130131function GetDiagnostic132{133param ($mp, $diagnosticID)134$diagnostic=$mp.GetDiagnostic($diagnosticID)135return$diagnostic136}137138function GetDiscoveryFromMG139{140param($mg, $criteria)141$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringDiscoveryCriteria($criteria)142$discovery=$mg.GetMonitoringDiscoveries($searchCriteria)[0]143$mp=$discovery.GetManagementPack()144return$mp.Name145}146147function GetClassFromMG148{149param($mg, $criteria)150$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringClassCriteria($criteria)151$class=$mg.GetMonitoringClasses($searchCriteria)[0]152return$class153}154155function GetRuleFromMG156{157param($mg, $criteria)158$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringRuleCriteria($criteria)159$rule=$mg.GetMonitoringRules($searchCriteria)[0]160$mp=$rule.GetManagementPack()161return$mp.Name162}163164function GetMonitorFromMG165{166param($mg, $criteria)167$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitorCriteria($criteria)168$monitor=$mg.GetMonitors($searchCriteria)[0]169$mp=$monitor.GetManagementPack()170return$mp.Name171}172173function GetDiagnosticFromMG174{175param($mg, $criteria)176$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringDiagnosticCriteria($criteria)177$diagnostic=$mg.GetMonitoringDiagnostics($searchCriteria)[0]178$mp=$diagnostic.GetManagementPack()179return$mp.Name180}181182function GetRecoveryFromMG183{184param($mg, $criteria)185$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringRecoveryCriteria($criteria)186$recovery=$mg.GetMonitoringRecoveries($searchCriteria)[0]187$mp=$recovery.GetManagementPack()188return$mp.Name189}190191function GetClassMPFromMG192{193param($mg, $criteria)194$searchCriteria= new-object Microsoft.EnterpriseManagement.Configuration.MonitoringClassCriteria($criteria)195$class=$mg.GetMonitoringClasses($searchCriteria)[0]196$mp=$class.GetManagementPack()197return$mp198}199200function GetWorkflow201{202param($mg, $mpID, $id, $type)203204$mp= GetManagementPack -mg $mg-mpID $mpID205206 try207 {208switch($type)209 {210 'discovery' {$workflow= GetDiscovery -mp $mp-discoveryID $id}211 'rule' {$workflow= GetRule -mp $mp-ruleID $id}212 'monitor' {$workflow= GetMonitor -mp $mp-monitorID $id}213 'recovery' {$workflow= GetRecovery -mp $mp-recoveryID $id}214 'diagnostic' {$workflow= GetDiagnostic -mp $mp-diagnosticID $id}215 }216 }217 catch218 {219 Write-Host "Workflow Not Found, Exiting:"$id-ForegroundColor Red220 Write-Host $_.Exception.Message -ForegroundColor Yellow221 exit222 }223return$workflow224}225226function GetOverridableParameters227{228param($workflow, $workflowType)229230$parameters= New-Object System.Collections.ArrayList231232#Property Overrides233switch ($workflowType)234 {235 'discovery' {$pValues= [enum]::GetNames([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty])}236 'rule' {$pValues= [enum]::GetNames([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty])}237 'monitor' {$pValues= [enum]::GetNames([Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorProperty])}238 'recovery' {$pValues= [enum]::GetNames([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty])}239 'diagnostic' {$pValues= [enum]::GetNames([Microsoft.EnterpriseManagement.Configuration.ManagementPackWorkflowProperty])}240 }241242foreach ($oin$pValues)243 {244$param= New-Object PSObject -Property @{245 Name =$o246 DisplayName =$o247 WorkflowType =$workflowType248 }249 [void]$parameters.Add($param)250 }251252#Configuration Overrides253switch ($workflowType)254 {255 'discovery' { $cValues=$workflow.GetOverrideableParametersByModule() }256 'rule' { $cValues=$workflow.GetOverrideableParametersByModule() }257 'monitor' { try {$cValues=$workflow.GetOverrideableParameters()} catch {} }258 'recovery' { $cValues=$workflow.GetOverrideableParametersByModule() }259 'diagnostic' { $cValues=$workflow.GetOverrideableParametersByModule() }260 }261262foreach ($modulein$cValues.Keys)263 {264foreach ($parameterin$cValues.$module)265 { 266$param= New-Object PSObject -Property @{267 Name =$parameter.Name268 DisplayName =$parameter.DisplayName269 WorkflowType =$workflowType270 ModuleName =$module.Name271 ParameterType =$parameter.ParameterType272 }273 [void]$parameters.Add($param)274 }275 }276277return$parameters278}279280#Adding SCOM Module281try { Import-Module OperationsManager } catch282{ 283 Write-Host "SCOM Module Not Found, Exiting"-ForegroundColor Red284 Write-Host $_.Exception.Message -ForegroundColor Yellow285 exit286}287288#Connect to SCOM Management Group289$MG= GetSCOMManagementGroup -ms $ManagementServer290291#Get Workflow Management Pack ID from Management Group292$WorkflowMPID= GetMPID -mg $MG-wfID $WorkflowID293294#Get Workflow Type295$WorkflowType= GetWorkflowType -mg $MG-mpID $WorkflowMPID-wfID $WorkflowID296297#Get Workflow298$WorkFlow= GetWorkflow -mg $mg-mpID $WorkflowMPID-id $WorkflowID-type $WorkflowType299300#Get Overridable Parameters301$Parameters= GetOverridableParameters -workflow $Workflow-workflowType $WorkflowType302303#Print Output304$Parameters| Format-Table Name, DisplayName, WorkflowType, ModuleName, ParameterType