Showing posts with label Query. Show all posts
Showing posts with label Query. Show all posts

Thursday, November 28, 2013

[OpsMgr 2012] How to find a specific rule/monitor/discovery in the console - SQL queries / Powershell command ( #SQL #Powershell #OpsMgr #OpsMgr2012 )


Sometimes in the Operations Manager Event log, we have some event/alert  for script error or WMI query error and all the time, the description give your the exact name of the rule/monitor/discovery that cause the issue. In SCOM console, you cannot find the rule/monitor/discovery by their exact name, only by the display name.



For example, here is an event 5500 we have on one server due to an invalid configuration for a monitor: Microsoft.SystemCenter.Agent.HealthService.PrivateBytesThreshold



Log Name:      Operations Manager
Source:        HealthService
Date:          11/28/2013 3:10:43 PM
Event ID:      5500
Task Category: Health Service
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      MyServer.MyDom.Dom
Description:
Frequent state change requests caused the incoming state change request to be dropped due to it being older than the currently recorded state change for this monitor. This could also be due to an invalid configuration for this monitor. 

Affected monitor: Microsoft.SystemCenter.Agent.HealthService.PrivateBytesThreshold
Instance: MyServer.MyDom.Dom
Instance ID: 293C0099-290F-C53C-340E-A5E710CA5B9F
Management Group: MyMgtGroup

Request generated time: 2013-11-28T15:10:43.1658766+01:00
Requested state: Success

Recorded time: 2013-11-28T15:20:35.7827611+01:00
Recorded state Success


To start investigation, you need to retrieve the display name of the rule/monitor/discovery. You can also execute SQL queries on views in the OpsMgrDB or PowerShell commands connected to your management group :

Rules:

SQL:

select DisplayName from ruleview where name = 'Rule.Name'

Command Shell:

(Get-SCOMRule | Where {$_.name -match 'Rule.Name'}).DisplayName

Monitors:

SQL:


select DisplayName from monitorview where Name = 'Monitor.Name'

Command Shell:

(Get-SCOMMonitor| Where {$_.name -match 'Monitor.Name'}).DisplayName

Discoveries:

SQL:

select DisplayName from DiscoveryView where name = 'Discovery.Name'

Command Shell:

(Get-SCOMDiscovery| Where {$_.name -match 'Discovery.Name'}).DisplayName


In our case, powershell command or SQL query give a display name (replace Monitor.Name by Microsoft.SystemCenter.Agent.HealthService.PrivateBytesThreshold in the line) : Health Service Private Bytes Threshold for monitor Microsoft.SystemCenter.Agent.HealthService.PrivateBytesThreshold

We can now retrieve the monitor in the SCOM console and try to investigate the issue  ! :)



This posting is provided "AS IS" with no warranties.

Saturday, September 29, 2012

[OpsMgr 2007 R2][OpsMgr 2012] Report to list all occurences of a specific alert in a given interval

The reports provided with System Center Operations Manager (SCOM) may sometimes seem particularly poor in terms of daily operations on the product. Today, Jean-Sébastien DUCHÊNE offers a report to list all occurrences of a specific alert in a given interval.
 
Beware: the proposed data depend on the retention time of the Data WareHouse.
Do not forget to create a datasource targeting to the data warehouse with security rights necessary to generate the report. This reports works with System Center Operations Manager 2007 R2, System Center 2012 Operations Manager and SQL Server 2008 RTM/R2.



This posting is provided "AS IS" with no warranties.

Monday, September 24, 2012

[OpsMgr 2007 R2][OpsMgr 2012] 2 reports to work on references between MPs

Here is a new link to an article from Jean-Sebastien DUCHENE who provide 2 new reports to work with references between management packs. Please find more report on his blog >>> Here <<<


The reports provided with System Center Operations Manager (SCOM) may sometimes seem particularly poor in terms of daily operations on the product. Today, I offer a report to track references between Unsealed MP and Sealed MP.
Here are the reports:
  • Management Pack - References by Override MP
  • Management Pack - References by Sealed MP
Do not forget to create a datasource targeting to the data warehouse with security rights necessary to generate the report. This reports works with System Center Operations Manager 2007 R2, System Center 2012 Operations Manager and SQL Server 2008 RTM/R2.

Here is the query:

SELECT distinct Tgt.ManagementPackSystemName As 'Sealed MP', Src.ManagementPackSystemName As 'Override MP'
FROM vManagementPackVersionReference
INNER JOIN vManagementPack As Tgt on ReferencedManagementPackRowId = Tgt.ManagementPackRowId
INNER join vManagementPackVersion on ReferencingManagementPackVersionRowId = vManagementPackVersion.ManagementPackVersionRowId
INNER JOIN vManagementPack As Src on vManagementPackVersion.ManagementPackRowId = Src.ManagementPackRowId
WHERE Src.SealedInd = 0
AND Tgt.ManagementPackSystemName NOT IN
('Microsoft.SystemCenter.Library',
'Microsoft.SystemCenter.InstanceGroup.Library',
'Microsoft.Windows.Library',
'System.Library',
'System.Health.Library')
ORDER BY Tgt.ManagementPackSystemName


This posting is provided "AS IS" with no warranties.

Thursday, September 20, 2012

[OpsMgr 2007 R2][OpsMgr 2012] Alerts associated to one MP Report

Source : - in this article >>> HERE <<<


The reports provided with System Center Operations Manager (SCOM) may sometimes seem particularly poor in terms of daily operations on the product. Today, I offer a report to list all alerts raised by a Management Pack in a given interval.
Beware: the proposed data depend on the retention time of the Data WareHouse.
Do not forget to create a datasource targeting to the data warehouse with security rights necessary to generate the report. This reports works with System Center Operations Manager 2007 R2, System Center 2012 Operations Manager  and SQL Server 2008 RTM/R2.


Here is the query:
SELECT     Distinct Alert.vAlert.AlertName AS 'Alert Name', Alert.vAlert.AlertDescription AS [Alert Description], Alert.vAlertDetail.TicketId AS 'Ticket ID',
                      CASE Alert.vAlert.Severity WHEN '0' THEN 'Information' WHEN '1' THEN 'Warning' WHEN '2' THEN 'Critical' END AS 'Severity',
                      CASE Alert.vAlert.Priority WHEN '0' THEN 'Low' WHEN '1' THEN 'Medium' WHEN '2' THEN 'High' END AS 'Priority', Alert.vAlert.RepeatCount AS 'Repeat Count',
                      Alert.vAlert.RaisedDateTime AS [Raised Date], COUNT(vAlert.AlertName)
FROM         Alert.vAlertDetail WITH (NOLOCK) INNER JOIN
                      Alert.vAlert WITH (NOLOCK) ON Alert.vAlertDetail.AlertGuid = Alert.vAlert.AlertGuid INNER JOIN
                      vRule WITH(NOLOCK) ON (vRule.RuleRowId = vAlert.WorkflowRowId AND vAlert.MonitorAlertInd = 0) INNER JOIN
                      vManagementPack WITH (NOLOCK) ON (vRule.ManagementPackRowId = vManagementPack.ManagementPackRowId)
WHERE     (vManagementPack.ManagementPackRowId = @MPiD)
AND (DATEADD(hh,DATEDIFF(hh,getutcdate(),getdate()),vAlert.RaisedDateTime)) between @startdate and @enddate
GROUP BY Alert.vAlert.AlertName, Alert.vAlert.AlertDescription, Alert.vAlertDetail.TicketId, Alert.vAlert.Severity, Alert.vAlert.Priority, Alert.vAlert.RaisedDateTime, Alert.vAlert.RepeatCount
UNION
 SELECT     Distinct Alert.vAlert.AlertName AS 'Alert Name', Alert.vAlert.AlertDescription AS [Alert Description], Alert.vAlertDetail.TicketId AS 'Ticket ID',
                      CASE Alert.vAlert.Severity WHEN '0' THEN 'Information' WHEN '1' THEN 'Warning' WHEN '2' THEN 'Critical' END AS 'Severity',
                      CASE Alert.vAlert.Priority WHEN '0' THEN 'Low' WHEN '1' THEN 'Medium' WHEN '2' THEN 'High' END AS 'Priority', Alert.vAlert.RepeatCount AS 'Repeat Count',
                      Alert.vAlert.RaisedDateTime AS [Raised Date], COUNT(vAlert.AlertName)
FROM         Alert.vAlertDetail WITH (NOLOCK) INNER JOIN
                      Alert.vAlert WITH (NOLOCK) ON Alert.vAlertDetail.AlertGuid = Alert.vAlert.AlertGuid INNER JOIN
                      vMonitor WITH(NOLOCK) ON (vMonitor.MonitorRowId = vAlert.WorkflowRowId AND vAlert.MonitorAlertInd = 1) INNER JOIN
                      vManagementPack WITH (NOLOCK) ON (vMonitor.ManagementPackRowId = vManagementPack.ManagementPackRowId)
WHERE     (vManagementPack.ManagementPackRowId = @MPiD)
AND (DATEADD(hh,DATEDIFF(hh,getutcdate(),getdate()),vAlert.RaisedDateTime)) between @startdate and @enddate
GROUP BY Alert.vAlert.AlertName, Alert.vAlert.AlertDescription, Alert.vAlertDetail.TicketId, Alert.vAlert.Severity, Alert.vAlert.Priority, Alert.vAlert.RaisedDateTime, Alert.vAlert.RepeatCount
ORDER BY  Alert.vAlert.RaisedDateTime DESC





This posting is provided "AS IS" with no warranties.

[OpsMgr 2007 R2][OpsMgr 2012] Hourly aggregated report on Performance Data for an agent

Source : - in this article >>> HERE <<<

The reports provided with System Center Operations Manager (SCOM) may sometimes seem particularly poor in terms of daily operations on the product. Today, I offer a report to select a performance rule of an agent to display a chart on a given interval. It will use hourly aggregated data.
Beware: the proposed data depend on the retention time of the Data WareHouse.
Do not forget to create a datasource targeting to the data warehouse with security rights necessary to generate the report. This reports works with System Center Operations Manager 2007 R2, System Center 2012 Operations Manager  and SQL Server 2008 RTM/R2.

Here is the query:

SELECT Distinct vPerformanceRuleInstance.InstanceName, vPerformanceRuleInstance.PerformanceRuleInstanceRowId FROM vRule
INNER JOIN vPerformanceRule WITH(NOLOCK) ON vRule.RuleRowId = vPerformanceRule.RuleRowId
INNER JOIN vPerformanceRuleInstance WITH(NOLOCK) ON vPerformanceRule.RuleRowId = vPerformanceRuleInstance.RuleRowId
INNER JOIN Perf.vPerfDaily WITH(NOLOCK) ON  vPerformanceRuleInstance.PerformanceRuleInstanceRowId = Perf.vPerfDaily.PerformanceRuleInstanceRowId
INNER JOIN vManagedEntity WITH(NOLOCK) ON Perf.vPerfDaily.ManagedEntityRowId = vManagedEntity.ManagedEntityRowId
WHERE  Path like '%' + @ManagedEntityId + '%' And vRule.RuleDefaultName = @RuleDefaultName
ORDER BY vPerformanceRuleInstance.InstanceName ASC 

 

This posting is provided "AS IS" with no warranties.

Thursday, September 13, 2012

[Orchestrator 2012] How to determine the version of System Center Orchestrator and its components

This article describes how to determine your current System Center Orchestrator version number and the corresponding product or service pack level.

How to determine the version of System Center Orchestrator Runbook Designer and Management Server

To determine the version of System Center Orchestrator Runbook Designer and the version of the Management Server that it is connected to, start the Runbook Designer application, connect to the desired Management Server and then click About on the Help menu.

Scroll down inside the Version Information box to see the versions of the various libraries installed on the Runbook Designer.

How to determine the version of System Center Orchestrator Runbook Servers

To determine the version of System Center Orchestrator Runbook Servers, start the Runbook Designer application, connect to the desired Management Server and then click Runbook Servers in the Connections pane.

How to determine the version of the System Center Orchestrator Database Schema

To determine the version of System Center Orchestrator Database Schema, start the SQL Server Management Studio application from your SQL Server or location where SQL Server Client Tools has been installed and connect to the SQL Database Engine instance that hosts the System Center Orchestrator database.

Click New Query and then execute the following SQL query:

USE <database> SELECT [DBVersion] FROM VERSION
Replace "<database>" with the name of the Orchestrator database.



System Center 2012 Orchestrator RTM

The following table lists the components and versions of System Center 2012 Orchestrator RTM.

ComponentProduct Version
System Center 2012 Orchestrator7.0.1154.0
Database Schema7.0.0
System Center 2012 Orchestrator Integration Toolkit7.0.359.0
Integration Pack for System Center 2012 Configuration Manager7.0.1298.0
Integration Pack for System Center 2012 Data Protection Manager7.0.1298.0
Integration Pack for System Center 2012 Operations Manager7.0.1298.0
Integration Pack for System Center 2012 Service Manager7.0.1298.0
Integration Pack for System Center 2012 Virtual Machine Manager7.0.1298.0
Integration Pack for System Center Configuration Manager 20077.0.1298.0
Integration Pack for System Center Data Protection Manager 20107.0.1298.0
Integration Pack for System Center Operations Manager 2007 R27.0.1298.0
Integration Pack for System Center Service Manager 20107.0.1298.0
Integration Pack for System Center Virtual Machine Manager 2008 R27.0.1298.0
Integration Pack for Microsoft Active Directory7.0.4465.5571
Integration Pack for IBM Tivoli Netcool/OMNIbus7.0.469.0
Integration Pack for HP iLO and OA7.0.264.0
Integration Pack for HP Operations Manager7.0.281.0
Integration Pack for HP Service Manager7.0.319.0
Integration Pack for VMware vSphere7.0.469.0

This posting is provided "AS IS" with no warranties.

Wednesday, September 12, 2012

[OpsMgr 2007 R2][OpsMgr 2012] Usefull Query / report to list all powershell sripts in your MPs

If you are working on an OpsMgr 2012 migration, this posting should be very interesting.
Once again Jean-Sebastien DUCHENE as worked on a very usefull report / SQL Query to help us to manage our migration. This time, we are able to list all discoveries, monitors, rules, tasks and recovery tasks that contain PowerShell scripts in your OpsMgr 2007 R2 environment. You'll also be able to retrieve MPs to modify to use the news SCOM 2012 cmdlet.

Here is the query provided by Jean-Sebastien DUCHENE to be executed on your Operations Manager DB :

SELECT ManagementPackView.FriendlyName As 'Management Pack'
   ,'Monitor' As 'Type'
   ,MonitorView.Name As 'Name'
      ,ManagedTypeView.Name As 'Class Targeted'
      ,Case Enabled When '4' Then 'Enabled'
      When '0' Then 'Disabled' END As 'Enabled'
      ,Category
      ,Priority
      ,'Null' As 'Module Name'
   ,SUBSTRING(SubString(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml)), CharIndex('<ScriptName>',SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml))),LEN(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml)))), CharIndex('>',SubString(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml)), CharIndex('<ScriptName>',SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml))),LEN(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml))))) + 1,LEN(SubString(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml)), CharIndex('<ScriptName>',SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml))),LEN(SubString(ConfigurationXml,0,CharIndex('</ScriptName>',ConfigurationXml))))))  As 'Script Name'
   ,ConfigurationXml As 'Module Configuration'
      ,MonitorView.LastModified
 FROM MonitorView
  INNER JOIN ManagementPackView WITH(NOLOCK) ON MonitorView.ManagementPackId = ManagementPackView.Id
  INNER JOIN ManagedTypeView WITH(NOLOCK) ON MonitorView.TargetMonitoringClassId = ManagedTypeView.Id
  WHERE  MonitorView.ConfigurationXml like '%.PS1%'
UNION
SELECT ManagementPackView.FriendlyName As 'Management Pack'
   ,'Rule' As 'Type'
   ,RuleView.Name As 'Name'
      ,ManagedTypeView.Name As 'Class Targeted'
      ,Case RuleView.Enabled When '4' Then 'Enabled'
      When '0' Then 'Disabled' END As 'Enabled'
      ,Category
      ,Priority
      ,RuleModuleName As 'Module Name'
   ,SUBSTRING(SubString(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration)), CharIndex('<ScriptName>',SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration)))), CharIndex('>',SubString(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration)), CharIndex('<ScriptName>',SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration))))) + 1,LEN(SubString(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration)), CharIndex('<ScriptName>',SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</ScriptName>',RuleModuleConfiguration)))))) + SUBSTRING(SubString(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration)), CharIndex('<CommandLine>',SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration)))), CharIndex('>',SubString(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration)), CharIndex('<CommandLine>',SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration))))) + 1,LEN(SubString(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration)), CharIndex('<CommandLine>',SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration))),LEN(SubString(RuleModuleConfiguration,0,CharIndex('</CommandLine>',RuleModuleConfiguration)))))) As 'Script Name'
   ,RuleModuleConfiguration As 'Module Configuration'
      ,RuleView.LastModified
  FROM RuleModule
  INNER JOIN RuleView WITH(NOLOCK) ON RuleModule.RuleId = RuleView.Id
  INNER JOIN ManagedTypeView WITH(NOLOCK) ON RuleView.TargetMonitoringClassId = ManagedTypeView.Id
  INNER JOIN ManagementPackView WITH(NOLOCK) ON RuleView.ManagementPackId = ManagementPackView.Id
  WHERE RuleModuleConfiguration like '%.PS1%'
  UNION
  SELECT ManagementPackView.FriendlyName As 'Management Pack'
   ,'Discovery' As 'Type'
   ,DiscoveryView.Name As 'Name'
      ,ManagedTypeView.Name As 'Class Targeted'
      ,Case Enabled When '4' Then 'Enabled'
      When '0' Then 'Disabled' END As 'Enabled'
      ,Case Category When '12' Then 'Discovery' Else 'Unknown' END 'Category'
      ,Priority
      ,Module.ModuleName As 'Module Name'
   ,SUBSTRING(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)))), CharIndex('>',SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))))) + 1,LEN(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)))))) + SUBSTRING(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)))), CharIndex('>',SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))))) + 1,LEN(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)))))) As 'Script Name'
      ,Module.ModuleConfiguration As 'Module Configuration'
      ,DiscoveryView.LastModified
  FROM DiscoveryView
  INNER JOIN Module WITH(NOLOCK) ON DiscoveryView.Id = Module.ParentId
  INNER JOIN ManagementPackView WITH(NOLOCK) ON DiscoveryView.ManagementPackId = ManagementPackView.Id
  INNER JOIN ManagedTypeView WITH(NOLOCK) ON DiscoveryView.TargetMonitoringClassId = ManagedTypeView.Id
  WHERE Module.ModuleConfiguration like '%.PS1%'
  UNION
  SELECT ManagementPackView.FriendlyName As 'Management Pack'
   ,'Recovery Task' As 'Type'
   ,RecoveryView.Name As 'Name'
      ,ManagedTypeView.Name As 'Class Targeted'
      ,Case Enabled When '4' Then 'Enabled'
      When '0' Then 'Disabled' END As 'Enabled'
      ,Case Category When '7' Then 'Custom' Else 'Unknown' END AS 'Category'
      ,'0' As 'Priority'
      ,Module.ModuleName As 'Module Name'
   ,SUBSTRING(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)))), CharIndex('>',SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))))) + 1,LEN(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))))))  As 'Script Name'
      ,Module.ModuleConfiguration As 'Module Configuration'
      ,RecoveryView.LastModified
  FROM RecoveryView
  INNER JOIN Module WITH(NOLOCK) ON RecoveryView.Id = Module.ParentId
  INNER JOIN ManagementPackView WITH(NOLOCK) ON RecoveryView.ManagementPackId = ManagementPackView.Id
  INNER JOIN ManagedTypeView WITH(NOLOCK) ON RecoveryView.TargetMonitoringClassId = ManagedTypeView.Id
  WHERE Module.ModuleConfiguration like '%.PS1%'
  UNION
  SELECT ManagementPackView.FriendlyName As 'Management Pack'
   ,'Task' As 'Type'
   ,TaskView.Name As 'Name'
      ,ManagedTypeView.Name As 'Class Targeted'
      ,Case Enabled When '4' Then 'Enabled'
      When '0' Then 'Disabled' END As 'Enabled'
      ,Case Category When '7' Then 'Custom' Else 'Unknown' END AS 'Category'
      ,'0' As 'Priority'
      ,Module.ModuleName As 'Module Name'
   ,SUBSTRING(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)))), CharIndex('>',SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))))) + 1,LEN(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)), CharIndex('<ScriptName>',SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</ScriptName>',Module.ModuleConfiguration)))))) + SUBSTRING(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)))), CharIndex('>',SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))))) + 1,LEN(SubString(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)), CharIndex('<CommandLine>',SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration))),LEN(SubString(Module.ModuleConfiguration,0,CharIndex('</CommandLine>',Module.ModuleConfiguration)))))) As 'Script Name'
      ,Module.ModuleConfiguration As 'Module Configuration'
      ,TaskView.LastModified
  FROM TaskView
  INNER JOIN Module WITH(NOLOCK) ON TaskView.Id = Module.ParentId
  INNER JOIN ManagementPackView WITH(NOLOCK) ON TaskView.ManagementPackId = ManagementPackView.Id
  INNER JOIN ManagedTypeView WITH(NOLOCK) ON TaskView.TargetMonitoringClassId = ManagedTypeView.Id
  WHERE Module.ModuleConfiguration like '%.PS1%'
  ORDER BY ManagementPackView.FriendlyName   


This posting is provided "AS IS" with no warranties.

Monday, September 10, 2012

[OpsMgr 2007][OpsMgr 2012] Usefull SQL Query / Report to retrieve what is targeting the RMS

has just published a SQL query and a report that will be very helpfull for the one that is preparing a migration to SCOM 2012.

Retrieving rules, monitors, tasks and discoveries that target the RMS will be usefull to decide what to do know :
  • if you have to modify your own management packs to target MS instead of RMS,
  • what provided MP is targeting the RMS (Microsoft Exchange Server 2010 Management Pack, Citrix EdgeSight Management Pack...) and also help you to decide if you have to install the RMS emulator in your new SCOM 2012 environment.


Please find his SQL query that must be launched on the Operations Manager DB.

DECLARE @ManagedType varchar(200)
SET @ManagedType = 'Root Management Server'
SELECT     ManagedTypeView.DisplayName, ManagementPackView.DisplayName AS 'Management Pack', 'Monitors' AS 'Type', ManagedEntityGenericView.DisplayName AS 'Target',
                      MonitorView.DisplayName AS 'Name', MonitorView.Category, MonitorView.Description,
                      CASE MonitorView.Enabled
                      WHEN '0' THEN 'Disabled'
                      WHEN '2' THEN 'Enabled'
                      WHEN '3' THEN 'Enabled'
                      WHEN '4' THEN 'Enabled'
                      End As 'Enabled', CONVERT(VARCHAR(20),
                      MonitorView.TimeAdded, 102) AS 'TimeAdded'
FROM         ManagementPackView INNER JOIN
                      MonitorView WITH(NOLOCK) ON ManagementPackView.Id = MonitorView.ManagementPackId INNER JOIN
                      ManagedEntityGenericView WITH(NOLOCK) ON MonitorView.TargetMonitoringClassId = ManagedEntityGenericView.MonitoringClassId INNER JOIN
                      TypedManagedEntity  WITH(NOLOCK) ON ManagedEntityGenericView.TypedManagedEntityId = TypedManagedEntity.TypedManagedEntityId INNER JOIN
                      ManagedTypeView  WITH(NOLOCK) ON TypedManagedEntity.ManagedTypeId = ManagedTypeView.Id
WHERE     (ManagedTypeView.DisplayName like '%' + @ManagedType + '%')
UNION
SELECT      ManagedTypeView_1.DisplayName, ManagementPackView_1.DisplayName AS 'Management Pack', 'Rules' AS 'Type', ManagedEntityGenericView_1.DisplayName AS 'Target',
                      RuleView.DisplayName AS 'Name', RuleView.Category, RuleView.Description, CASE RuleView.Enabled
                      WHEN '0' THEN 'Disabled'
                      WHEN '2' THEN 'Enabled'
                      WHEN '3' THEN 'Enabled'
                      WHEN '4' THEN 'Enabled'
                      End As 'Enabled', CONVERT(VARCHAR(20), RuleView.TimeAdded, 102)
                      AS 'TimeAdded'
FROM         ManagementPackView AS ManagementPackView_1 INNER JOIN
                      RuleView WITH(NOLOCK) ON ManagementPackView_1.Id = RuleView.ManagementPackId INNER JOIN
                      ManagedEntityGenericView AS ManagedEntityGenericView_1 WITH(NOLOCK) ON
                      RuleView.TargetMonitoringClassId = ManagedEntityGenericView_1.MonitoringClassId INNER JOIN
                      TypedManagedEntity AS TypedManagedEntity_1 WITH(NOLOCK) ON ManagedEntityGenericView_1.TypedManagedEntityId = TypedManagedEntity_1.TypedManagedEntityId INNER JOIN
                      ManagedTypeView As ManagedTypeView_1 WITH(NOLOCK) ON TypedManagedEntity_1.ManagedTypeId = ManagedTypeView_1.Id
WHERE     (ManagedTypeView_1.DisplayName like '%' + @ManagedType + '%')
UNION
SELECT      ManagedTypeView_2.DisplayName, ManagementPackView_2.DisplayName AS 'Management Pack', 'Discoveries' AS 'Type', ManagedEntityGenericView_2.DisplayName AS 'Target',
                      DiscoveryView.DisplayName AS 'Name', case DiscoveryView.Category when 12 THEN 'Discovery' END, DiscoveryView.Description, CASE DiscoveryView.Enabled
                      WHEN '0' THEN 'Disabled'
                      WHEN '2' THEN 'Enabled'
                      WHEN '3' THEN 'Enabled'
                      WHEN '4' THEN 'Enabled'
                      End As 'Enabled', CONVERT(VARCHAR(20), DiscoveryView.TimeAdded, 102)
                      AS 'TimeAdded'
FROM         ManagementPackView AS ManagementPackView_2 INNER JOIN
                      DiscoveryView WITH(NOLOCK) ON ManagementPackView_2.Id = DiscoveryView.ManagementPackId INNER JOIN
                      ManagedEntityGenericView AS ManagedEntityGenericView_2 WITH(NOLOCK) ON
                      DiscoveryView.TargetMonitoringClassId = ManagedEntityGenericView_2.MonitoringClassId INNER JOIN
                      TypedManagedEntity AS TypedManagedEntity_2 WITH(NOLOCK) ON ManagedEntityGenericView_2.TypedManagedEntityId = TypedManagedEntity_2.TypedManagedEntityId INNER JOIN
                      ManagedTypeView As ManagedTypeView_2 WITH(NOLOCK) ON TypedManagedEntity_2.ManagedTypeId = ManagedTypeView_2.Id
WHERE     (ManagedTypeView_2.DisplayName like '%' + @ManagedType + '%')
UNION
SELECT      ManagedTypeView_3.DisplayName, ManagementPackView_3.DisplayName AS 'Management Pack', 'Tasks' AS 'Type', ManagedEntityGenericView_3.DisplayName AS 'Target',
                      RecoveryView.DisplayName AS 'Name', case RecoveryView.Category  when 17 THEN 'Recovery' END, RecoveryView.Description, CASE RecoveryView.Enabled
                      WHEN '0' THEN 'Disabled'
                      WHEN '2' THEN 'Enabled'
                      WHEN '3' THEN 'Enabled'
                      WHEN '4' THEN 'Enabled'
                      End As 'Enabled', CONVERT(VARCHAR(20), RecoveryView.TimeAdded, 102)
                      AS 'TimeAdded'
FROM         ManagementPackView AS ManagementPackView_3 INNER JOIN
                      RecoveryView WITH(NOLOCK) ON ManagementPackView_3.Id = RecoveryView.ManagementPackId INNER JOIN
                      ManagedEntityGenericView AS ManagedEntityGenericView_3 WITH(NOLOCK) ON
                      RecoveryView.TargetMonitoringClassId = ManagedEntityGenericView_3.MonitoringClassId INNER JOIN
                      TypedManagedEntity AS TypedManagedEntity_3 WITH(NOLOCK) ON ManagedEntityGenericView_3.TypedManagedEntityId = TypedManagedEntity_3.TypedManagedEntityId INNER JOIN
                      ManagedTypeView As ManagedTypeView_3 WITH(NOLOCK) ON TypedManagedEntity_3.ManagedTypeId = ManagedTypeView_3.Id
WHERE     (ManagedTypeView_3.DisplayName like '%' + @ManagedType + '%')
ORDER BY 'Management Pack'







This posting is provided "AS IS" with no warranties.

Thursday, February 9, 2012

[SQL] Get SCOM Groups members using a SQL Query on OperationsManager DB

Here is a short query that is very usefull to list all member of a SCOM group. Use it on your OperationsManager DB :
  1. select DisplayName from RelationShip r with (nolock)
  2. inner join basemanagedentity bme with (nolock) on bme.BaseManagedEntityId = R.TargetEntityId
  3. Where SourceEntityId in (
  4.             select BaseManagedEntityId from basemanagedentity with (nolock)
  5.             where DisplayName LIKE '%GroupName%')
  6. Order by DisplayName

This posting is provided "AS IS" with no warranties.

Wednesday, February 1, 2012

[Powershell] Query Database by using a powershell function

Here is a usefull function to query a DB from a powershell script.

  1. function RunQueryOnDB ($DBServer, $DBCatalog, $DBQuery, $DBUid, $DBUidPWD)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SqlQuery = $DBQuery
  6. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  7. $SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlCatalog; Uid = $DBUid; Pwd = $DBUidPWD"
  8. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  9. $SqlCmd.CommandText = $SqlQuery
  10. $SqlCmd.Connection = $SqlConnection
  11. $SQlCmd.CommandTimeout = 120
  12. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  13. $SqlAdapter.SelectCommand = $SqlCmd
  14. $DSet = New-Object System.Data.DataSet
  15. $SqlAdapter.Fill($DSet) | out-null
  16. $SqlConnection.Close()
  17. $DSet.Tables[0]
  18. }

How to use it :
  1. # --------- set the DB Server and Catalog
  2. $DBServerName = "MyDBServer"
  3. $DBName = "MyDBNAme"
  4. # --------- Set the Query
  5. $Query = "Select PrincipalName from MyDB"
  6. # --------- Set the credentials to use to query the DB
  7. $Account = "MyAccount"
  8. $pwd = "MyPassword"
  9. # --------- Variable initialization
  10. $SCOMGrpName = "MyGroupName" 
  11. # --------- Query The DB
  12. $Result = RunQueryOnDB $DBServerName $DBName $Query $Account $pwd
The script wil return a table $Result that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Groups members using a SQL Query

Here is a new powershell script that I had to use to develop MPs. Retieving SCOM Groups members (displayName in the exemple)by using the SCOM DB.
  1. function GetSCOMGroupMembers ($SCOMGrp, $DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SCOMGroup = $SCOMGrp
  6. $SQLQuery = "select DisplayName from RelationShip r with (nolock)
  7. inner join basemanagedentity bme  with (nolock) on bme.BaseManagedEntityId = R.TargetEntityId
  8. Where SourceEntityId in (
  9. select BaseManagedEntityId from basemanagedentity with (nolock)
  10. where DisplayName LIKE '%$SCOMGroup%')"
  11. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  12. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  13. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  14. $SqlCmd.CommandText = $SQLQuery
  15. $SqlCmd.Connection = $SqlConnection
  16. $SQlCmd.CommandTimeout = 120
  17. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  18. $SqlAdapter.SelectCommand = $SqlCmd
  19. $DSet = New-Object System.Data.DataSet
  20. $SqlAdapter.Fill($DSet) | out-null
  21. $SqlConnection.Close()
  22. $DSet.Tables[0]
  23. }

How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = "MyServer"
  3. $SCOMCatalog = "OperationsManager" 
  4. # --------- Variable initialization
  5. $SCOMGrpName = "MyGroupName" 
  6.  # --------- Read SCOM group and get member count
  7. $GroupMembersList = GetScomGroupMembers $SCOMGrpName $SCOMServer $SCOMCatalog
The script wil return a table $GroupMembersList that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Groups using a SQL Query

Today, I'll add a new powershell script that I had to use for a developped MP. Retieving SCOM Groups by using the SCOM DB.
  1. Function GetSCOMGroupsInSQL ($DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SQLQuery = "select distinct SCOMGroup = convert(varchar(100), upper(rtrim(ltrim(BME.Displayname))))"
  6. $SQLQuery += " from BaseManagedEntity BME"
  7. $SQLQuery += " left join dbo.ManagedTypeView T1 on (BME.BaseManagedEntityId = T1.Id)"
  8. $SQLQuery += " Left join dbo.Relationship R1 on(BME.BaseManagedEntityId=R1.Sourceentityid)"
  9. $SQLQuery += " left join BaseManagedEntity ME2 on (ME2.BaseManagedEntityId=R1.targetentityid)"
  10. $SQLQuery += " left join dbo.ManagedTypeView T2 on(ME2.BaseManagedEntityId=T2.id)"
  11. $SQLQuery += " where (T1.Name like 'UINameSpace%.Group' or T1.Name like '%MySpecificGroupName%')"
  12. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  13. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  14. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  15. $SqlCmd.CommandText = $SqlQuery
  16. $SqlCmd.Connection = $SqlConnection
  17. $SQlCmd.CommandTimeout = 120
  18. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  19. $SqlAdapter.SelectCommand = $SqlCmd
  20. $DSet = New-Object System.Data.DataSet
  21. $SqlAdapter.Fill($DSet) | out-null
  22. $SqlConnection.Close()
  23. $DSet.Tables[0]
  24. }
How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = $Config.Groups.SCOMDB.SCOMDBServerName
  3. $SCOMCatalog = $Config.Groups.SCOMDB.SCOMDBName
  4. # --------- Query SCOM DB to get Agent list and Group List
  5. $GroupList = GetSCOMGroupsInSQL $SCOMServer $SCOMCatalog
The script wil return a table $GroupList that can also be re-used.

This posting is provided "AS IS" with no warranties.

[Powershell] Get SCOM Agents using a SQL Query

Today, I'll add a new powershell script that I had to use for a developped MP. Retieving SCOM agents by using the SCOM DB instead of Get-Agent cmdlet.
The aim was to have a very fast answer of the script and using the Get-Agent cmdlet was really too long.

  1. Function GetSCOMAgentsInSQL ($DBServer, $DBCatalog)
  2. {
  3. $SqlServer = $DBServer
  4. $SqlCatalog = $DBCatalog
  5. $SQLQuery =  "SELECT distinct(B.displayname)"
  6. $SQLQuery += " FROM TypedManagedEntity T WITH(NOLOCK)"
  7. $SQLQuery += " JOIN BaseManagedEntity B WITH(NOLOCK)    ON B.BaseManagedEntityId = T.BaseManagedEntityId"
  8. $SQLQuery += " WHERE T.ManagedTypeId = dbo.fn_ManagedTypeId_MicrosoftSystemCenterAgent()"
  9. $SQLQuery += " order by 1"
  10. $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  11. $sqlConnection.ConnectionString = "Server = $sqlserver; Database = $sqlcatalog; Integrated Security = True"
  12. $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  13. $SqlCmd.CommandText = $SqlQuery
  14. $SqlCmd.Connection = $SqlConnection
  15. $SQlCmd.CommandTimeout = 120
  16. $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  17. $SqlAdapter.SelectCommand = $SqlCmd
  18. $DSet = New-Object System.Data.DataSet
  19. $SqlAdapter.Fill($DSet) | out-null
  20. $SqlConnection.Close()
  21. $DSet.Tables[0]
  22. }

How to use it :
  1. # --------- Read the SCOMDB Server and Catalog
  2. $SCOMServer = $Config.Groups.SCOMDB.SCOMDBServerName
  3. $SCOMCatalog = $Config.Groups.SCOMDB.SCOMDBName
  4. # --------- Query SCOM DB to get Agent list and Group List
  5. $AgentList = GetSCOMAgentsInSQL $SCOMServer $SCOMCatalog
The script wil return a table $AgentList that can also be re-used.

This posting is provided "AS IS" with no warranties.

Friday, January 27, 2012

[SQL & SCOM] List SCOM groups for a list of servers

SELECT TargetMonitoringObjectDisplayName, SourceMonitoringObjectDisplayName AS 'Group'
FROM RelationshipGenericView
WHERE TargetMonitoringObjectDisplayName in ('MyServerFullName',
'MyServerFullName1')
AND (SourceMonitoringObjectDisplayName IN
(SELECT ManagedEntityGenericView.DisplayName
FROM ManagedEntityGenericView INNER JOIN
(SELECT BaseManagedEntityId
FROM BaseManagedEntity WITH (NOLOCK)
WHERE (BaseManagedEntityId = TopLevelHostEntityId) AND (BaseManagedEntityId NOT IN
(SELECT R.TargetEntityId
FROM Relationship AS R WITH (NOLOCK) INNER JOIN
dbo.fn_ContainmentRelationshipTypes() AS CRT ON R.RelationshipTypeId = CRT.RelationshipTypeId
WHERE (R.IsDeleted = 0)))) AS GetTopLevelEntities ON
GetTopLevelEntities.BaseManagedEntityId = ManagedEntityGenericView.Id INNER JOIN
(SELECT DISTINCT BaseManagedEntityId
FROM TypedManagedEntity WITH (NOLOCK)
WHERE (ManagedTypeId IN
(SELECT DerivedManagedTypeId
FROM dbo.fn_DerivedManagedTypes(dbo.fn_ManagedTypeId_Group()) AS fn_DerivedManagedTypes_1))) AS GetOnlyGroups ON
GetOnlyGroups.BaseManagedEntityId = ManagedEntityGenericView.Id))
ORDER BY 'Group'

Result will be like :


TargetMonitoringObjectDisplayNameGroup
MyServerFullName1agent group
MyServerFullNameagent group
MyServerFullName1Agent Managed Computer Group
MyServerFullNameAgent Managed Computer Group
MyServerFullName1All Windows Computers
MyServerFullNameAll Windows Computers
MyServerFullName1IIS 2003 Computer Group
MyServerFullNameIIS 2003 Computer Group
MyServerFullName1IIS Computer Group
MyServerFullNameIIS Computer Group
MyServerFullName1Windows Server 2003 Computer Group
MyServerFullNameWindows Server 2003 Computer Group
MyServerFullName1Windows Server Computer Group
MyServerFullNameWindows Server Computer Group
MyServerFullName1Windows Server Instances Group
MyServerFullNameWindows Server Instances Group

This posting is provided "AS IS" with no warranties.

System Center Operations Manager 2007 usefull SQL Queries

I will try to often update this post with the SQLqueries I've found or developped for specific report needs.

Last update : 2012/03/07

This posting is provided "AS IS" with no warranties.

Thursday, December 1, 2011

[OpsMgr 2007] Timeout running Remove-DisabledMonitoringObject cmdlet in System Center Operations Manager

I've read a lot and seen a lot of cases like mine - I mean remove-disabledmonitoringobject cmdlet get the error "The requested operation timed out" but it seems that nobody has been lucky to found how to fix the issue. We have openned a Micorsoft case on this issue a lot of monthes ago and since the begining of the week, we are now able to run the cmdlet without any error.

This resolution given by Microsoft for an openned case will not be part of the CU6.
The resolution has been found too late !


First, here is our configuration - approximatly 3000 agents in CU3. We don't have upgraded to CU4 and we soon upgrade to CU5. SQL 2008 for the DBs.

The first thinking of why the cmdlet is timing out was the number of overrides was too much for the SDK to process before the thirty minute WCF(Windows Connection Framework) timeout occurs.

Within our production environment there are approximately 140000 DiscoverySources which need analyse be the cmdlet to know if the associated discovered types need to be removed or not. We have a pre-production environnemnt with less number of agents and only 40000 DiscoverySources on wich the cmdlet is well working.

To reduce the number of Discovery sources we have analysed all the MP we have and it appeared that OCS MP was responsible for almost 40% of the hugh number of DiscoverySources. The OCS MP has nineteen discoveries targeted at Windows Server Computer class enabled by default. On each discoveries we have an override on a group to disable disovery for the group members. A discoverysource entry is created for each discovery-to-target-entity mapping.
We have also :  19 * ~3000 agents = 57000 discoverysources just for OCS MP.
When overrides are done one theses discoveries, the enabled states must calculated for all discoverysources !

I've worked to remove some overrides and also to reduce the enabled state calculation for the DiscoverySources but the cmdlet was always timed out.

The next way to fix the issue was to let Microsoft have an other review of the code and SQL involved to see if they can make some efficiencies in the way they do this. I've also been asked to run 2 queries on the SCOM Database :
I’ve also run the following queries :

  1. SELECT COUNT (Distinct [DiscoverySource].[DiscoverySourceId])
  2. FROM dbo.DiscoverySource
  3. INNER JOIN dbo.ModuleOverride ON ModuleOverride.ParentId = DiscoverySource.DiscoveryRuleId
  4. AND ModuleOverride.OverrideableParameterId = dbo.fn_MPObjectId(NULL, NULL, N'Enabled')
  5. AND (ParentType = 'Discovery' OR ParentType = 'Rule')
  6. join DiscoverySourceToTypedManagedEntity dstme
  7. on discoverysource.DiscoverySourceId = dstme.DiscoverySourceId
  8. WHERE DiscoverySource.IsDeleted = 0
  9. AND ModuleOverride.Value = 'false'

  1. SELECT COUNT (Distinct [DiscoverySource].[DiscoverySourceId])
  2. FROM dbo.DiscoverySource
  3. INNER JOIN dbo.ModuleOverride ON ModuleOverride.ParentId = DiscoverySource.DiscoveryRuleId
  4. AND ModuleOverride.OverrideableParameterId = dbo.fn_MPObjectId(NULL, NULL, N'Enabled')
  5. AND (ParentType = 'Discovery' OR ParentType = 'Rule')
  6. join DiscoverySourceToTypedManagedEntity dstme
  7. on discoverysource.DiscoverySourceId = dstme.DiscoverySourceId
  8. WHERE DiscoverySource.IsDeleted = 0
Given the numbers returned by the queries Microsoft support suspects the step below will allow the cmdlet to complete and await your results.
Here is also what I've been asked to do :
  • Run the SQL against the OperationsManager DB.

  1. DECLARE @querydef XML
  2. SET @querydef =
  3. N'<QueryDefinitions xmlns="urn:DataAccess" xmlns:dal="urn:DataAccess" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:DataAccess QueryDefinition.xsd">
  4. <QueryDefinition>
  5.   <Name>DiscoverySourcesEligibleForDeletionDueToOverrides</Name>
  6.   <ObjectName>DiscoverySourcesEligibleForDeletionDueToOverrides</ObjectName>
  7.   <UsedBy Component="Sdk" />
  8.   <Description>Selects discovery sources that *may* be invalid due to applied overrides.</Description>
  9.   <DataObject xsi:type="SelectType">
  10.     <Column>
  11.       <Name>DiscoverySourceId</Name>
  12.       <Source>DiscoverySource</Source>
  13.       <Type>uniqueidentifier</Type>
  14.     </Column>
  15.     <Column>
  16.       <Name>DiscoverySourceType</Name>
  17.       <Source>DiscoverySource</Source>
  18.       <Type>tinyint</Type>
  19.       <EnumType>Microsoft.EnterpriseManagement.Mom.Modules.DataItems.Discovery.DiscoverySourceType</EnumType>
  20.       <EnumLeastValue>Rule</EnumLeastValue>
  21.       <EnumGreatestValue>ConfigService</EnumGreatestValue>
  22.     </Column>
  23.     <Column>
  24.       <Name>DiscoveryRuleId</Name>
  25.       <Source>DiscoverySource</Source>
  26.       <Type>uniqueidentifier</Type>
  27.     </Column>
  28.     <Column>
  29.       <Name>BoundManagedEntityId</Name>
  30.       <Source>DiscoverySource</Source>
  31.       <Type>uniqueidentifier</Type>
  32.     </Column>
  33.     <Argument>Distinct</Argument>
  34.     <Source>
  35.       <Table>
  36.         <Name>DiscoverySource</Name>
  37.         <Owner>dbo</Owner>
  38.         <Type>Table</Type>
  39.       </Table>
  40.       <Join>
  41.         <Type>Inner</Type>
  42.         <Table>
  43.           <Name>ModuleOverride</Name>
  44.           <Owner>dbo</Owner>
  45.           <Type>Table</Type>
  46.         </Table>
  47.         <JoinCondition>ModuleOverride.ParentId = DiscoverySource.DiscoveryRuleId AND ModuleOverride.OverrideableParameterId = dbo.fn_MPObjectId(NULL, NULL, N''Enabled'') AND (ParentType = ''Discovery'' OR ParentType = ''Rule'')</JoinCondition>
  48.       </Join>
  49.       <Join>
  50.         <Type>Inner</Type>
  51.         <Table>
  52.           <Name>DiscoverySourceToTypedManagedEntity</Name>
  53.           <Owner>dbo</Owner>
  54.           <Type>Table</Type>
  55.         </Table>
  56.         <JoinCondition> discoverysource.DiscoverySourceId = DiscoverySourceToTypedManagedEntity.DiscoverySourceId</JoinCondition>
  57.       </Join>
  58.     </Source>
  59.     <Conditional>
  60.       <Condition>
  61.         <Expression>DiscoverySource.IsDeleted = 0 AND ModuleOverride.Value = ''false''</Expression>
  62.       </Condition>
  63.     </Conditional>
  64.   </DataObject>
  65. </QueryDefinition>
  66. </QueryDefinitions>'
  67. INSERT INTO dbo.[DataAccessLayerSetting]([SettingType], [SettingData]) VALUES (0, @querydef)



The impact of this change is when the cmdlet is run, it will now use the SQL query inserted in the Data.AccessLayerSetting table instead of the Original SQL query which is compiled into one dll. This table allows us to override the in-built queries, as it is read on OMSDK service restart.Coming back to the origicnal SQL is very easy, just remove the entry in the Data.AccessLayerSetting table and restart the SDK.

  • Restart the OpsMgr SDK service.
  • Run the remove-disabledmonitoringobject cmdlet and report back on the success or failure of it.
I use to launch the cmdlet like this (in a short PS1):
  1. get-managementserver | select ManagementGroup -unique
  2. get-date
  3. remove-disabledmonitoringobject
  4. get-date
That permit to show in the same few line the OpsMgr group, the dates before and after the cmdlet has run.


 Unfortunatly the 2 first time I've launched the remove-disabledmonitoringobject cmdlet, it went to a new error :

  1. >get-date
  2. Monday, November 28, 2011 8:27:16 AM
  3. PS Monitoring:\
  4. >remove-disabledmonitoringobject
  5. Remove-DisabledMonitoringObject : Microsoft.EnterpriseManagement.Common.DiscoveryDataFromRuleTargetedToDeletedMonitoringObjectException: Discovery data has been received from a rule targeted at a non-existent monitoring object id.
  6. MonitoringObjectId: c1537246-ec53-cc7c-b45f-aed87f06bc7f
  7. RuleId: 66b6d462-535f-cab6-eb14-b24fc79dfb75
  8.    at Microsoft.EnterpriseManagement.DataAbstractionLayer.InstanceSpaceOperations.DeleteDisabledDiscoverySources()
  9.    at Microsoft.EnterpriseManagement.ManagementGroup.DeleteDisabledMonitoringObjects()
  10.    at Microsoft.EnterpriseManagement.OperationsManager.ClientShell.RemoveDisabledMonitoringObjectCmdlet.ProcessRecord()
  11. At line:1 char:32
  12. + remove-disabledmonitoringobject <<<<
  13.     + CategoryInfo          : InvalidOperation: (Microsoft.Enter...ingObjectCmdlet   :RemoveDisabledMonitoringObjectCmdlet) [Remove-DisabledMonitoringObject], Disc
  14.   overyDataFr...ObjectException    + FullyQualifiedErrorId : ExecutionError,Microsoft.EnterpriseManagement.Operat
  15.    ionsManager.ClientShell.RemoveDisabledMonitoringObjectCmdlet
  16. PS Monitoring:\
  17. >get-date
  18. Monday, November 28, 2011 8:48:55 AM
I've also report this again to the microsoft support and wait any answer. That particular seems to be known and the cmdlet completed without error on the second run. In my case, the second run of the cmdlet found a different object which caused again the error and as in the first run it set the original object’s IsDeleted property to 1. It appears that the cmdlet attempts remove some objects twice, and it's failing on the second attempt.
I've launched a third time the cmdlet and it ended in success ! 





This posting is provided "AS IS" with no warranties.

This posting is provided "AS IS" with no warranties.