Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Monday, 6 February 2012

Installing SQL 2008 R2 from a remote share after .Net Framework 4.0

I built a new fully patched VM template the other day for use in my lab and for deploying to private clouds in my System Center lab environment, but noticed some strange behaviour after deploying a new VM based on the template and trying to install SQL 2008 R2.

Every time I tried to run the setup I kept getting the following message:

Managed SQL Server Landing Page has stopped working


Doing a search online for similar issues around setup and landingpage.exe didn't yield a great deal of solutions.

Back tracking I decided to narrow down some of the changes I had made to the image, specifically around the installed updates.

After uninstalling .Net Framework 4.0 SQL setup appeared to work without a hitch, but putting .Net 4.0 back on yielded the same result.

After a bit more searching, I came across a TechNet forum post that pointed me in the direction of this blog post about using CasPol to fully trust a share: http://blogs.msdn.com/b/shawnfa/archive/2004/12/30/344554.aspx

It turns out that when trying to install SQL 2008 R2 from a file share with .Net 4.0 installed will result in this landingpage.exe error so the choices are:
  1. Install SQL 2008 R2 from a CD/DVD/ISO
  2. Copy the SQL 2008 R2 install files locally and install
  3. Use CasPol to trust the share
I choose to use the CasPol method as I have all my install files stored in my DSL used by MDT & ConfigMgr so would rather use this than digging out disks or mounting ISO's.

The command I used was:
CasPol.exe -m -ag 1.2 -url file://\\<Server>/<Share>/* FullTrust

Run this from C:\Windows\Microsoft.NET\Framework64\v4.0.30319

This worked on one of my servers, however, another one I tried started throwing errors then about FixSQLRegistryKey during the pre-req checks.

The same forum post also mentions a more permanent fix, so I took the plunge and added/changed the following line to the listed config files in the source files for SQL:

<runtime>
   <legacyCasPolicy enabled="false" />
   <loadFromRemoteSources enabled="true"/>
</runtime>

Files:
  • setup.exe.config
  • setup100.exe.config
  • fixsqlregistrykey_ia64.exe.config
  • fixsqlregistrykey_x64.exe.config
  • fixsqlregistrykey_x86.exe.config
  • landingpage.exe.config

This basically has the effect of ignoring the CAS policies introduced with .Net 4.0 and enabling the use of remote shares.

Not pretty, but worked for me ;)

Original Forum Post:
http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/3bc7cebb-2264-4e51-878b-0cce193c2780

Thanks Min Keng!

Interestingly, this issue has been highlighted to Microsoft via Connect as far back as July 2010 and still has no official fix other than to uninstall .Net or run from the local machine.
http://connect.microsoft.com/SQLServer/feedback/details/573043/sql-server-2008-r2-cumulative-updates-wont-install-with-dotnet-framework-4-0-30319

Monday, 5 December 2011

Configuration Manager 2012 RC now supports SQL 2008 R2

As of 03/12/11 you'll be pleased to know that SQL Server 2008 R2 Service Pack 1 is now supported for use with Configuration Manager 2012 Release Candidate 1. 

In addition to Service Pack 1, you will also need to install Cumulative Update 3 (CU3) for SQL Server 2008 R2 SP1, as well as the hotfix described in KB2603910: http://support.microsoft.com/kb/2603910.

However, please note that the hotfix for SQL 2008 R2 has currently been pulled again for some reason and isn't available at the link above, I'll update this post when it is, until then you would need to contact MS to obtain the hotfix.

*Updated 12/12/11* The hotfix for SQL 2008 R2 is now available.  Thanks Mr Anonymous commentor.

Friday, 2 December 2011

How to move a SCVMM 2012 database to another SQL server

I'm not exactly re-inventing the wheel here as it's the same process for Virtual Machine Manager 2012 as it was for 2008 R2, but I thought I'd post about it anyway.

This isn't a common thing to need to do, but I found myself in the position today where I wanted to move the database that was on a local SQL install on a SCVMM 2012 server up onto a new SQL Cluster I had just finished building.

So these are the steps I took to move the database:
  1. Take a snapshot of the server (assuming it's a VM)
  2. Take a backup of the existing VMM DB
  3. Uninstall VMM and choose the Retain Database option
  4. Detach the VMM DB from the local SQL instance
  5. Copy the VMM DB files across to the new SQL Server
  6. On the remote SQL server, attach the VMM db
  7. Re-install SCVMM 2012 and when prompted, point it at the new SQL server, selecting to use an existing database (the one you imported) 
Easy!  Now you're free to uninstall SQL as and when.

Thursday, 7 July 2011

Using the Microsoft Solutions Accelerator Dashboards with SCOM

I've done a few of posts on using the SCCM dashboards to display SCOM information, but Kevin Greene has taken it to a whole new level......

http://kevingreeneitblog.blogspot.com/2011/07/scom-dashboards-conclusion-and.html

His series of posts not only cover in great detail how to install and configure both the ConfigMgr Dashboard and the OpsMgr Service Level Dashboard but also shows how to customise the look and feel as well as integrate the SLA Dash into the main SCCM Dash to provide a much more seamless approach.

My hat is well and truly tipped to you Kevin :)

Wednesday, 6 July 2011

How to find activities in your runbooks that have changed in the new Orchestrator

Adam Hall has just posted a really useful SQL query that can be run against your existing Opalis database to help you understand what objects you currently use that are no longer available in Orchestrator.

This is a brilliant piece of information as it could save you a boat load of time before you upgrade by identifying which run books you need to tweak in advance rather than having to import each one with fingers crossed hoping it doesn't break.

The original post is here, but I've replicated the SQL code below for my own benefit so I know where it is without having to search ;)

Please bear in mind that Orchestrator is still in Beta, so by RTM there could be more objects to add to this SQL query.

Select
policies.[Name] as [Policy Name],
objects.[Name] as [Object Name]
From
[Objects] objects join
[Policies] policies
on objects.[ParentID]=policies.[UniqueID]
Where
objects.objecttype = '2081B459-88D2-464A-9F3D-27D2B7A64C5E' or
objects.objecttype = '6F0FA888-1969-4010-95BC-C0468FA6E8A0' or
objects.objecttype = '8740DB49-5EE2-4398-9AD1-21315B8D2536' or
objects.objecttype = '19253CC6-2A14-432A-B4D8-5C3F778B69B0' or
objects.objecttype = '9AB62470-8541-44BD-BC2A-5C3409C56CAA' or
objects.objecttype = '292941F8-6BA7-4EC2-9BC0-3B5F96AB9790' or
objects.objecttype = '98AF4CBD-E30E-4890-9D26-404FE24727D7' or
objects.objecttype = '2409285A-9F7E-4E04-BFB9-A617C2E5FA61' or
objects.objecttype = 'B40FDFBD-6E5F-44F0-9AA6-6469B0A35710' or
objects.objecttype = '9DAF8E78-25EB-425F-A5EF-338C2940B409' or
objects.objecttype = 'B5381CDD-8498-4603-884D-1800699462AC' or
objects.objecttype = 'FCA29108-14F3-429A-ADD4-BE24EA5E4A3E' or
objects.objecttype = '7FB85E1D-D3C5-41DA-ACF4-E1A8396A9DA7' or
objects.objecttype = '3CCE9C71-51F0-4595-927F-61D84F2F1B5D' or
objects.objecttype = '96769C11-11F5-4645-B213-9EC7A3F244DB' or
objects.objecttype = '6FED5A55-A652-455B-88E2-9992E7C97E9A' or
objects.objecttype = '9C1DF967-5A50-4C4E-9906-C331208A3801' or
objects.objecttype = 'B40FDFBD-6E5F-44F0-9AA6-6469B0A35710' or
objects.objecttype = '829A951B-AAE9-4FBF-A6FD-92FA697EEA91' or
objects.objecttype = '1728D617-ACA9-4C96-ADD1-0E0B61104A9E' or
objects.objecttype = 'F3D1E70B-D389-49AD-A002-D332604BE87A' or
objects.objecttype = '2D907D60-9C25-4A1C-B950-A31EB9C9DB5F' or
objects.objecttype = '6A083024-C7B3-474F-A53F-075CD2F2AC0F' or
objects.objecttype = '4E6481A1-6233-4C82-879F-D0A0EDCF2802' or
objects.objecttype = 'BC49578F-171B-4776-86E2-664A5377B178'

Wednesday, 11 May 2011

SCOM Distributed App Health Dashboard

Since I've been doing a bit of work recently on System Center Dashboards I thought I'd quickly post this snippet that I've just done.

SELECT  distinct   BaseManagedEntity.DisplayName, case State.HealthState when 1 then 'Healthy' when 2 then 'Warning' when 3 then 'Critical' when 4 then 'Not Monitored' else 'Unknown' end as Status
FROM State INNER JOIN
BaseManagedEntity ON State.BaseManagedEntityId = BaseManagedEntity.BaseManagedEntityId
where (BaseManagedEntity.FullName like 'Service_%'
or BaseManagedEntity.DisplayName = 'Active Directory Topology Root'
or BaseManagedEntity.DisplayName = 'Certificate Services'
or BaseManagedEntity.DisplayName = 'ConfigMgr 2007 Site Hierarchy'
or BaseManagedEntity.DisplayName = 'Operations Manager Management Group')
and BaseManagedEntity.Name is NULL
or (BaseManagedEntity.DisplayName = 'Exchange Service' and State.HealthState <> '0')

This gives a result that looks like this:

If you take out the case statement so it returns 1,2 & 3's instead of Healthy, Warning & Critical then this SQL snippet can be used to create a RAG scorecard in the System Center Dashboard that produces a result like this:


Also (for my reference) Kevin Holman has a ton of useful SCOM SQL queries:
http://blogs.technet.com/b/kevinholman/archive/2007/10/18/useful-operations-manager-2007-sql-queries.aspx

Tuesday, 12 April 2011

System Center Dashboards - SCCM & SCOM SQL Snippets

Since I had to redo our System Center Dashboard today, I took the time to pull off most of our SQL Snippets and thought I'd post them here.

Some of these have been posted in other places, and I take no credit for all of them, but I forget half the places I got them from.  So if they are your SQL and you're reading this, thank you.  Leave a comment and I'll add a reference to you.


Configuration Manager SQL Snippets


Overall Machine Count

Type - Linear Gauge
Title - Overall Machines Count
Description -
Actual Value - OverallClientCount
Operator - <
Goal - 3000
Scale Start – 0
Scale End - 3100
Aggregation - Min

SELECT
count(DISTINCT name0) AS OverallClientCount
FROM v_R_System
WHERE client0=1 and obsolete0=0 and active0=1


Machines Count By Network

Type - Pie Chart

Title - Machines Count By Network
Legend - Network
Y-Axis - ClientCount

 
SELECT
CASE sms_assigned_sites0
WHEN 'SC1' THEN 'Network 1'

WHEN 'SC2' THEN 'Network 2'
END AS "Network", count(distinct name0) as ClientCount
FROM v_RA_System_SMSAssignedSites sas join v_R_System sys on sas.resourceID=sys.resourceID
WHERE client0=1 AND obsolete0=0 AND Active0=1
GROUP BY CASE sms_assigned_sites0


WHEN 'SC1' THEN 'Network1'
WHEN 'SC2' THEN 'Network 2'
 

END
ORDER by 2 desc


Machines Count By Operating System

Type - Pie Chart

Title - Machines Count By Operating System
Legend - Operating System
Y-Axis - Client Count
 
SELECT TOP 5
OPSYS.Caption0 as 'Operating System', COUNT(*) AS 'Client Count'

FROM v_GS_OPERATING_SYSTEM OPSYS
INNER JOIN v_R_System sys on OPSYS.ResourceID = sys.ResourceID
INNER JOIN v_RA_System_SMSAssignedSites Asys on sys.ResourceID = Asys.ResourceID
WHERE
sys.client0=1 AND sys.obsolete0=0 AND sys.active0=1 AND
Asys.SMS_Assigned_Sites0 LIKE @SiteCode
GROUP BY OPSYS.Caption0
ORDER BY Count(*) desc


Machines Count By Domains

Type - Pie Chart

Title - Machines Count By Domains
Legend - Clientdomain
Y-Axis - ClientCount
 
SELECT TOP 10
Resource_domain_OR_Workgr0 as ClientDomain, count(distinct name0) as ClientCount
FROM v_R_System
WHERE client0=1 AND obsolete0=0 AND Active0=1
GROUP BY Resource_domain_OR_Workgr0
ORDER BY 2 desc


Machines Count By Server/Workstation OS Type

Type - Pie Chart

Title - Machines Count By Server/Workstation OS Type
Legend - ClientOSType
Y-Axis - ClientCount
 
SELECT
ClientOSType = CASE
WHEN Operating_System_Name_and0 LIKE '%workstation%' THEN 'Total WorkStation OS'
WHEN Operating_System_Name_and0 LIKE '%server%' THEN 'Total Server OS'
END,
COUNT(*)AS ClientCount
FROM v_r_system (NOLOCK)
WHERE
client0 =1 AND obsolete0 =0 AND Active0=1
AND Operating_System_Name_and0 IS NOT NULL
GROUP BY CASE
WHEN Operating_System_Name_and0 LIKE '%workstation%' THEN 'Total WorkStation OS'

WHEN Operating_System_Name_and0 LIKE '%server%' THEN 'Total Server OS'
END


Machines Count By 32/64 bit OS Type

Type - Pie Chart

Title - Machines Count By 32/64 bit OS Type
Legend - MachineType
Y-Axis - ClientCount
 
SELECT systemtype00 as MachineType, count(distinct os.name0) as ClientCount
FROM Computer_System_DATA pro
JOIN v_R_System os on os.resourceid=pro.machineid
WHERE

os.client0=1 AND os.obsolete0=0 AND Active0=1
AND systemtype00 in ('X86-based PC','x64-based PC')
GROUP BY systemtype00
ORDER BY 2 desc


Machines Count By Desktops/Notebooks Type

Type - Pie Chart

Title - Machines Count By Desktops/Notebooks Type
Legend - Workstation Type
Y-Axis – ClientCount

SELECT  
CASE ChassisTypes0
                      WHEN '1' THEN 'Server'
                      WHEN '2' THEN 'Server'
                      WHEN '3' THEN 'Desktop'
                      WHEN '4' THEN 'Low-Profile Desktop'
                      WHEN '5' THEN 'Pizza-Box'
                      WHEN '6' THEN 'Desktop'
                      WHEN '7' THEN 'Desktop'
                      WHEN '8' THEN 'Mobile Device'
                      WHEN '9' THEN 'Mobile Device'
                      WHEN '10' THEN 'Mobile Device'
                      WHEN '11' THEN 'Hand-Held'
                      WHEN '12' THEN 'Mobile Device'
                      WHEN '13' THEN 'All-in-One'
                      WHEN '14' THEN 'Sub-Notebook'
                      WHEN '15' THEN 'Desktop'
                      WHEN '16' THEN 'Desktop'
                      WHEN '17' THEN 'Server'
                      WHEN '18' THEN 'Mobile Device'
                      WHEN '19' THEN 'Sub-Chassis'
                      WHEN '20' THEN 'Bus-Expansion chassis'
                      WHEN '21' THEN 'Peripheral Chassis'
                      WHEN '22' THEN 'Storage Chassis'
                      WHEN '23' THEN 'Server'
                      WHEN '24' THEN 'Sealed-Case PC'
                     WHEN '65' THEN 'Tablet PC'                    
 ELSE 'Unknown'
END AS "Workstation Type", count(distinct sys.name0) as ClientCount from
v_GS_SYSTEM_ENCLOSURE ENC   
        INNER JOIN 
            v_R_System SYS ON ENC.ResourceID = SYS.ResourceID   
WHERE
    sys.client0=1 AND sys.obsolete0=0 AND active0=1
GROUP BY
    CASE ChassisTypes0
                      WHEN '1' THEN 'Server'
                      WHEN '2' THEN 'Server'
                      WHEN '3' THEN 'Desktop'
                      WHEN '4' THEN 'Low-Profile Desktop'
                      WHEN '5' THEN 'Pizza-Box'
                      WHEN '6' THEN 'Desktop'
                      WHEN '7' THEN 'Desktop'
                      WHEN '8' THEN 'Mobile Device'
                      WHEN '9' THEN 'Mobile Device'
                      WHEN '10' THEN 'Mobile Device'
                      WHEN '11' THEN 'Hand-Held'
                      WHEN '12' THEN 'Mobile Device'
                      WHEN '13' THEN 'All-in-One'
                      WHEN '14' THEN 'Sub-Notebook'
                      WHEN '15' THEN 'Desktop'
                      WHEN '16' THEN 'Desktop'
                      WHEN '17' THEN 'Server'
                      WHEN '18' THEN 'Mobile Device'
                      WHEN '19' THEN 'Sub-Chassis'
                      WHEN '20' THEN 'Bus-Expansion chassis'
                      WHEN '21' THEN 'Peripheral Chassis'
                      WHEN '22' THEN 'Storage Chassis'
                      WHEN '23' THEN 'Server'
                      WHEN '24' THEN 'Sealed-Case PC'
                      WHEN '65' THEN 'Tablet PC'
                      ELSE 'Unknown'
   END
ORDER BY 2 desc


Machines By Physical/Virtual Type

Type - Pie Chart

Title - Machines By Physical/Virtual Type
Legend - Machine Type
Y-Axis - ClientCount
 
SELECT
CASE Model0
    WHEN 'VMware Virtual Platform' THEN 'Virtual Machine'
    ELSE 'Phyical Machine'
END AS "Machine Type",
COUNT(distinct sys.name0) as ClientCount
FROM Computer_System_DATA ass join v_R_System sys on ass.machineID=sys.resourceID
WHERE
    client0=1 AND obsolete0=0 AND Active0=1
GROUP BY
    CASE Model0
        WHEN 'VMware Virtual Platform' THEN 'Virtual Machine'
        ELSE 'Phyical Machine'
END
ORDER BY 2 desc



PrinterCount

Type - Bar Chart

Title - Count of Printers
Description -
Legend - Type
Y-Axis - Count of Devices

SELECT     'Local' AS Type, COUNT(dbo.v_GS_PRINTER_DEVICE.DeviceID0) AS [Count of Devices]
FROM         dbo.v_GS_PRINTER_DEVICE INNER JOIN
                      dbo.v_R_System ON dbo.v_GS_PRINTER_DEVICE.ResourceID = dbo.v_R_System.ResourceID
WHERE     (dbo.v_R_System.Name0 LIKE '%PC%' OR
                      dbo.v_R_System.Name0 LIKE '%tb%' OR
                      dbo.v_R_System.Name0 LIKE '%lt%') AND (v_GS_PRINTER_DEVICE.PortName0 LIKE 'LPT%' OR
                      v_GS_PRINTER_DEVICE.PortName0 LIKE 'USB%' OR
                      v_GS_PRINTER_DEVICE.PortName0 LIKE 'DOT%' OR
                      v_GS_PRINTER_DEVICE.PortName0 LIKE 'ESD%')

UNION

SELECT     TOP (100) PERCENT 'Network' as [Type], COUNT(dbo.v_GS_PRINTER_DEVICE.DeviceID0) AS [Count of Devices]
FROM         dbo.v_GS_PRINTER_DEVICE INNER JOIN
                      dbo.v_R_System ON dbo.v_GS_PRINTER_DEVICE.ResourceID = dbo.v_R_System.ResourceID
WHERE     (dbo.v_R_System.Name0 LIKE '%##PrintServerName##%') 


MFDCount

Type - Bar Chart

Title - Count of MultiFunction Devices
Description -
Legend - Type
Y-Axis - Count of MFDs

SELECT     'MultiFunction Devices' AS Type, COUNT(v_GS_PRINTER_DEVICE.DriverName0) AS [Count of MFDs]
FROM         v_GS_PRINTER_DEVICE INNER JOIN
                      v_R_System ON v_GS_PRINTER_DEVICE.ResourceID = v_R_System.ResourceID
WHERE     (v_GS_PRINTER_DEVICE.DriverName0 LIKE 'Sharp%') AND (v_R_System.Name0 = '##PrintServerName##')


HWandSWInventoryLast7Days
Type - Data Grid
Title - Client Count and % with Hardware & Software Inventory in last 96 hrs. by Site
 
Header Text
Column
Site Code
AssignedSite
Total Clients
TotalActiveClients

Type - Linear Gauge
Title - Client % with Hardware Inventory in last 96 Hours
Description -
Actual Value - HW Percentage
Operator - >=
Goal - 80
Scale Start - 0
Scale End - 100
Aggregation - Average

 
Type - Linear Gauge
Title - Client % with Hardware Inventory in last 96 Hours
Description -
Actual Value - HW Percentage
Operator - >=
Goal - 80
Scale Start – 0
Scale End - 100
Aggregation - Average

DECLARE  @olddate datetime
        ,@NullVal datetime
SET @olddate = DATEADD(day,-7, GETUTCDATE())

SELECT  sites.SMS_Assigned_Sites0   AS AssignedSite
       ,TotalSys.Total AS TotalActiveClients
       ,SuccSys.Succ AS HWSuccess
       ,SuccSW.Succ AS SWSuccess
       ,CONVERT(decimal(5,2),(SuccSys.Succ*100.00/TotalSys.Total)) AS 'HW Percentage'
       ,CONVERT(decimal(5,2),(SuccSW.Succ*100.00/TotalSys.Total))  AS 'SW Percentage'

  FROM v_RA_system_smsassignedsites sites
       INNER JOIN (
                   SELECT  sit.SMS_Assigned_Sites0 AS AssSite
                          ,COUNT(DISTINCT sis.Netbios_Name0) AS Succ
                     FROM v_RA_System_SMSAssignedSites sit
                          INNER JOIN v_R_System sis
                             ON sit.ResourceID = sis.ResourceID
                          INNER JOIN v_gs_workstation_status sts
                             ON sis.ResourceID = sts.ResourceID
                            AND sis.Client0 = 1
                            AND sis.Obsolete0 = 0
                            AND sis.Active0 = 1  
                            AND sts.LastHWScan > @olddate
                    GROUP BY sit.sms_assigned_sites0
                   ) SuccSys
          ON sites.SMS_Assigned_Sites0 = SuccSys.AssSite
       INNER JOIN (
                   SELECT  sit.SMS_Assigned_Sites0 AS AssSite
                          ,COUNT(DISTINCT sis.Netbios_Name0) AS Succ
                     FROM v_RA_System_SMSAssignedSites sit
                          INNER JOIN v_R_System sis
                             ON sit.ResourceID = sis.ResourceID
                          INNER JOIN v_GS_LastSoftwareScan sts
                             ON sis.ResourceID = sts.ResourceID
                            AND sis.Client0 = 1
                            AND sis.Obsolete0 = 0
                            AND sis.Active0 = 1
                            AND sts.LastScanDate > @olddate
                    GROUP BY sit.SMS_Assigned_Sites0
                   ) SuccSW
          ON SuccSW.AssSite = sites.SMS_Assigned_Sites0
       INNER JOIN (
                   SELECT  sit.SMS_Assigned_Sites0 AS AssSite
                          ,COUNT(DISTINCT sis.Netbios_Name0) AS Total
                     FROM v_RA_System_SMSAssignedSites sit
                          INNER JOIN v_R_system sis
                             ON sit.ResourceID = sis.ResourceID
                            AND sis.Client0 = 1
                            AND sis.Obsolete0 = 0
                            AND sis.Active0 = 1
                    GROUP BY sit.SMS_Assigned_Sites0
                   ) TotalSys
          ON sites.SMS_Assigned_Sites0 = TotalSys.Asssite
GROUP BY  sites.SMS_Assigned_Sites0
          ,TotalSys.Total
          ,SuccSys.Succ
          ,SuccSW.Succ
ORDER BY 4 DESC

ClientCommsInLast24Hrs Type - Data Grid
Title - Client Count for WSUS Scan, Heartbeat and MP Communication in last 24 hrs
 
Header Text
Column
Site Code
SiteCode
Total Clients
TotalClient

Type - Bar Chart
Title - Client Count for WSUS Scan, Heartbeat and MP Communication in last 24 hrs
Description -
Legend - SiteCode
Y-Axis - TotalClient, ScanSuccess, Heartbeat, MPComunicationSuccess
 
DECLARE @olddate datetime
SET @olddate=DATEADD(hour,-24, GETUTCDATE())
SELECT  tot.SiteCode
       ,tot.TotalClient
       ,ptc.ScanTotal [ScanSuccess]
       ,CONVERT(decimal(5,2),(ptc.ScanTotal*100.00/tot.TotalClient)) [ScanSuccessPerc]
       ,hrt.HBCount [Heartbeat]
       ,CONVERT(decimal(5,2),(hrt.HBCount*100.00/tot.TotalClient)) [HeartbeatPerc]
       ,mpc.MPComunicatonSuccess
       ,mpc.MPComunicatonFailure
       ,mpc.MPComunicatonTotal
      ,CONVERT(decimal(5,2),(mpc.MPComunicatonSuccess*100.00/tot.TotalClient)) MPComunicatonSuccessPerc
  FROM (
        SELECT  sit.SMS_Assigned_Sites0 [SiteCode]
               ,COUNT(1) TotalClient
          FROM v_R_System sis
               INNER JOIN v_RA_System_SMSAssignedSites sit
                  ON sis.ResourceID = sit.ResourceID
                 AND sis.Client0 = 1
                 AND sis.Obsolete0 = 0
                 AND sis.Active0 = 1
           GROUP BY sit.SMS_Assigned_Sites0
        ) tot
        LEFT OUTER JOIN (
                         SELECT  sit.SMS_Assigned_Sites0 [SiteCode]
                                ,COUNT(1) [ScanTotal]
                           FROM v_updateScanStatus upp
                                INNER JOIN v_statenames stn
                                   ON upp.LastScanState = stn.StateID
                                  AND stn.TopicType = '501'
                                  AND stn.StateName = 'Scan completed'
                                INNER JOIN v_RA_System_SMSAssignedSites sit
                                   ON upp.ResourceID = sit.ResourceID
                                  AND upp.LastScanPackageLocation LIKE 'http%'
                                  AND upp.LastScanTime > @olddate
                          GROUP BY  upp.LastScanState
                                   ,sit.SMS_Assigned_Sites0
                         ) ptc
          ON tot.SiteCode = ptc.SiteCode
        LEFT OUTER JOIN (
                         SELECT  sit.SMS_Assigned_Sites0 AS [SiteCode]
                                ,COUNT (sis.name0) AS [HBCount]
                           FROM v_R_System sis
                                INNER JOIN (
                                            SELECT a.ResourceID, a.AgentSite, b.AgentTime
                                              FROM v_AgentDiscoveries a
                                                   INNER JOIN (
                                                               SELECT ResourceID, MAX(AgentTime) AS AgentTime
                                                                 FROM v_AgentDiscoveries
                                                                WHERE AgentName LIKE '%Heartbeat%'
                                                                  AND AgentTime > @olddate
                                                                GROUP BY ResourceID
                                                               ) b
                                                      ON a.ResourceID = b.ResourceID
                                                     AND a.AgentTime = b.AgentTime
                                            ) hrt
                                   ON sis.ResourceId = hrt.ResourceID
                                INNER JOIN v_RA_System_SMSAssignedSites sit
                                   ON sis.resourceID = sit.ResourceID
                                  AND sis.Client0 = 1
                                  AND sis.Obsolete0 = 0
                          GROUP BY sit.SMS_Assigned_Sites0
                         ) hrt
          ON tot.SiteCode = hrt.SiteCode
        LEFT OUTER JOIN (
                         SELECT  sub.[Site]                                         AS [SiteCode]
                                ,SUM(CASE sub.HealthState WHEN 1 THEN sub.Cnt END)  AS [MPComunicatonSuccess]
                                ,SUM(CASE sub.HealthState WHEN 2 THEN sub.Cnt END)  AS [MPComunicatonFailure]
                                ,SUM(sub.Cnt)                                       AS [MPComunicatonTotal]
                           FROM (
                                 SELECT  sit.SiteCode [Site]
                                        ,chs.HealthState
                                        ,COUNT(chs.HealthState) [Cnt]
                                   FROM v_Site sit
                                        INNER JOIN v_ClientHealthState chs
                                           ON sit.SiteCode = chs.AssignedSiteCode
                                          AND chs.HealthType = '1000'
                                          AND chs.LastHealthReportDate > @olddate
                                          AND sit.[Type] = 2
                                  GROUP BY  sit.SiteCode
                                           ,chs.HealthState
                                 ) sub
                          GROUP BY sub.[Site]
                         ) mpc
 ON tot.SiteCode = mpc.SiteCode


ClientDeploymentErrorMsg

Type - Data Grid

Title - .
 
Header Text
Column
Last Message State ID
LastMessageStateID
Last State Message Description
StateDescription
Client Counts
ClientsCount


Type - Pie Chart
Title - Client Deployment Error Messages for Last 7 days
Description -
Legend - LastMessageStateID
Y-Axis - ClientsCount
 
select Top 10 StateDescription,
    LastMessageStateID, count(*) 'ClientsCount'
from v_ClientDeploymentState
where LastMessageStateID not in ('400','700','100','500')
    and DeploymentBeginTime >DATEADD(day,-8, getdate())
group by StateDescription, LastMessageStateID
order by 3 desc



InactiveAndObsoleteClientCount
Type - Data Grid
Title - % of Obsolete & Inactive Client Count
Header Text
Column
Site Code
AssignedSite
Total Clients (including inactive & obsolete)
Total Count


Type - Linear Gauge
Title - % of Inactive Client Count
Description -
Actual Value - % of Inactive Clients
Operator - <
Goal - 25
Scale Start – 0
Scale End - 100
Aggregation - Average

Type - Linear Gauge

Title - % of Obsolete Client Count
Description -
Actual Value - % of Obsolete Clients

Operator - <
Goal - 25
Scale Start - 0
Scale End - 100
Aggregation - Average
 
select sub.AssignedSite,
        sum(sub.cnt ) 'Total Count',
        SUM(CASE SUB.ACTIVE0 when 1 then SUB.cnt END) AS 'Total Active Clients',
        SUM(CASE SUB.ACTIVE0 when 0 then SUB.cnt END) AS 'Total Inactive Clients',
        SUM(CASE SUB.obsolete0 when 1 then SUB.cnt END) AS 'Total Obsolete Clients'
        ,ROUND((CAST(SUM(CASE SUB.ACTIVE0 when 0 then SUB.cnt END) AS float) / SUM(sub.Cnt)) * 100,2) AS '% of Inactive Client Count'
        ,ROUND((CAST(SUM(CASE SUB.obsolete0 when 1 then SUB.cnt END) AS float) / SUM(sub.Cnt)) * 100,2) AS '% of Obsolete Client Count'
FROM
    (select sit.sms_assigned_sites0 AssignedSite,
            sys.active0,sys.obsolete0 ,
            COUNT(*) cnt
  from v_R_System sys
  join v_RA_System_SMSAssignedSites sit  on sys.resourceID=sit.resourceID
    and (sys.Active0 is not null and sys.Obsolete0 is not null)
group by sit.sms_assigned_sites0,sys.active0,sys.obsolete0
)sub
group by sub.AssignedSite



ClientHealthStateErrorMessagesforLast7Days
Type - Data Grid
Title - .
Header Text
Column
Error Code
ErrorCode
Error Symbolic Name
SymbolicName


Type - Pie Chart
Title - Client Health State Error Messages for Last 7 days
Description -
Legend - ErrorCode
Y-Axis - ClientCount
 
select Top 10 CH.ErrorCode,
    CU.Description,CU.[SymbolicName],
    COUNT(*) as ClientClient
from v_ClientHealthState CH
left join SCCM_NELC.dbo.Custom_Message_descriptions CU on CH.ErrorCode=cu.errorcode
where healthstate != 1
    and LastHealthReportDate >DATEADD(day,-8, getdate())
Group by CH.ErrorCode,CU.Description,CU.[SymbolicName]
order by 4 desc


WindowsUpdateScanErrorforLast7days
Type - Data Grid
Title - .
Header Text
Column
Symbolic Name
SymbolicName
Last Error Code
LastErrorCode


Type - Pie Chart
Title - Windows Update Scan Error for Last 7 days
Description -
Legend - LastErrorCode
Y-Axis - ClientCount
 
select Top 10 LastErrorCode,
    CU.Description,CU.[SymbolicName],
    COUNT(*) as ClientCount
from v_updateScanStatus up
    join v_r_system sys on sys.resourceid = up.resourceid
    left join SCCM_NELC.dbo.Custom_Message_descriptions CU on up.LastErrorCode=cu.errorcode
where lastscantime >DATEADD(day,-8, getutcdate())
    and lastscantime < getutcdate()
    and LastErrorCode != 0
group by LastErrorCode,CU.Description,CU.[SymbolicName]
order by 4 desc


ClientErrorStatusMessagesforlast7days
Type - Data Grid
Title - .
Header Text
Column
Client Component
Component
Message ID
MessageID


Type - Pie Chart
Title - Top 10 Client Error Status Messages for last 7 days
Description -
Legend - MessageID
Y-Axis - Count
 
SELECT top 10 MessageID
    , sm.Severity
    , COUNT(*) AS 'Count'
    , MAX(Time) AS 'LastOccurred'
    , Component
    ,cu.Description
FROM v_StatusMessage sm WITH (NOLOCK)
join SCCM_NELC.dbo.Custom_Message_descriptions CU on sm.messageid=cu.errorcode
WHERE ModuleName = 'SMS Client'
    AND sm.Severity != 1073741824
    AND Time > DATEADD(DAY, -8, GetDate())    
GROUP BY MessageID, MachineName, Component, sm.Severity, cu.description
ORDER BY 3 desc


UnapprovedClientCountbySite

Type - Column Chart

Title - Unapproved Client Count by Site
Description -
Legend - SMS_Assigned_Sites0
Y-Axis - ClientCount

Select AssignedSite.SMS_Assigned_Sites0,
    COUNT(*) as ClientCount
from ClientKeyData CD
join v_RA_System_SMSAssignedSites AssignedSite on AssignedSite.resourceID=CD.RecordID
where CD.ApprovalStatus <> 1
group by AssignedSite.SMS_Assigned_Sites0
order by 2 desc


Servers By Physical/Virtual Type

Type - Pie Chart

Title - Servers By Physical/Virtual Type
Description -
Legend - Machine Type
Y-Axis - ClientCount

SELECT     TOP (100) PERCENT CASE Model0 WHEN 'VMware Virtual Platform' THEN 'Virtual Machine' ELSE 'Phyical Machine' END AS [Machine Type], COUNT(sys.Name0)
                      AS ClientCount
FROM         dbo.Computer_System_DATA AS ass INNER JOIN
                      dbo.v_R_System AS sys ON ass.MachineID = sys.ResourceID INNER JOIN
                      dbo.v_FullCollectionMembership ON sys.ResourceID = dbo.v_FullCollectionMembership.ResourceID
WHERE     (sys.Client0 = 1) AND (sys.Obsolete0 = 0) AND (sys.Active0 = 1) AND (dbo.v_FullCollectionMembership.CollectionID = 'SMS000DS')
GROUP BY CASE Model0 WHEN 'VMware Virtual Platform' THEN 'Virtual Machine' ELSE 'Phyical Machine' END
ORDER BY COUNT(sys.Name0) DESC


Operating System and Service Pack

Type - Data Grid
Title - .
Header Text
Column
Operating System
Operating System
Service Pack
Service Pack
Count
Count


Type - Pie Chart
Title - Operating System and Service Pack
Description -
Legend - Operating System
Y-Axis - Count
 
SELECT OPSYS.Caption0 as 'Operating System', OPSYS.CSDVersion0 as 'Service Pack', COUNT(*) AS 'Count'
FROM v_GS_OPERATING_SYSTEM OPSYS
inner join v_R_System sys on OPSYS.ResourceID=sys.ResourceID
GROUP BY OPSYS.Caption0, OPSYS.CSDVersion0
ORDER BY OPSYS.Caption0, OPSYS.CSDVersion0

 

Operations Manager SQL Snippets  

Number of Alerts Per Day (28 Days)

Type - Bar Chart

Title - Number of Alerts
Description - Per Day (28 Days)
Legend - Date
Y-Axis - Alerts

USE OperationsManagerDW
SELECT CONVERT(VARCHAR(10), DBCreatedDateTime, 101) AS Date, COUNT(*) AS Alerts
FROM  Alert.vAlert
WHERE (DBCreatedDateTime BETWEEN DATEADD(day, -27, GETDATE()) AND GETDATE())
GROUP BY CONVERT(VARCHAR(10), DBCreatedDateTime, 101)
ORDER BY Date DESC


Top 20 Alerts by Alert Count

Type - Pie Chart

Title - Top 20 Alerts by Alert Count
Description -
Legend - AlertStringName
Y-Axis - AlertCount

SELECT TOP 20 SUM(1) AS AlertCount, AlertStringName
FROM Alertview WITH (NOLOCK)
WHERE TimeRaised is not NULL
GROUP BY AlertStringName
ORDER BY AlertCount DESC


Top 20 Alerts by Repeat Count

Type - Pie Chart
Title - Top 20 Alerts
Description - by Repeat Count
Legend - AlertStringName
Y-Axis - RepeatCount
 
SELECT TOP 20 SUM(RepeatCount+1) AS RepeatCount, AlertStringName
FROM Alertview WITH (NOLOCK)
WHERE Timeraised is not NULL
GROUP BY AlertStringName
ORDER BY RepeatCount DESC

Servers Generating the Most Events

Type - Pie Chart

Title - Servers Generating the Most Events
Description -
Legend - ComputerName
Y-Axis - TotalEvents

SELECT top 20 LoggingComputer as ComputerName, COUNT(*) AS TotalEvents
FROM EventallView with (NOLOCK)
GROUP BY LoggingComputer
ORDER BY TotalEvents DESC


Number of Monitored Servers

Type - Circular Gauge

Title - Number of Monitored Servers
Description -
Actual Value - NumManagedComps
Operator - <
Goal - 200
Scale Start – 0
Scale End - 250
Aggregation - Min

SELECT COUNT(*) AS NumManagedComps FROM (
SELECT bme2.BaseManagedEntityID
FROM BaseManagedEntity bme WITH (NOLOCK)
INNER JOIN BaseManagedEntity bme2 WITH (NOLOCK) ON bme2.BaseManagedEntityID = bme.TopLevelHostEntityID
WHERE bme2.IsDeleted = 0
AND bme2.IsDeleted = 0
AND bme2.BaseManagedTypeID = (SELECT TOP 1 ManagedTypeID FROM ManagedType WHERE TypeName = 'microsoft.windows.computer')
GROUP BY bme2.BaseManagedEntityID
) AS Comps


Number of Active Alerts

Type - Circular Gauge
Title - Number of Active Alerts
Description -
Actual Value - ActiveAlerts
Operator - <
Goal - 20
Scale Start - 0
Scale End - 100
Aggregation - Min

SELECT COUNT(1) AS ActiveAlerts FROM Alert WHERE ResolutionState = '0'


Number of Alerts by Type

Type - Column Chart

Title - Number of Alerts by Type
Description -
Legend - State
Y-Axis - GroupCount

SELECT [State] = CASE ManagedEntityGenericView.HealthState
    WHEN 1 THEN 'Healthy'
    WHEN 2 THEN 'Warning'
    WHEN 3 THEN 'Critical'
    ELSE 'Unknown'
    END
    , COUNT(1) AS GroupCount

    FROM ManagedEntityGenericView INNER JOIN
    ManagedTypeView ON ManagedEntityGenericView.MonitoringClassId = ManagedTypeView.Id
    WHERE (ManagedTypeView.Name LIKE 'Microsoft.Windows.Computer')
    GROUP BY ManagedEntityGenericView.HealthState
    ORDER BY GroupCount


Total Number of Alerts Closed by User

Type - Pie Chart

Title - Total Number of Alerts Closed by User
Description -
Legend - statesetbyuserid
Y-Axis - Number of Alerts

select statesetbyuserid, count(*) as 'Number of Alerts'
from Alert.vAlertResolutionState ars
where resolutionstate = '255'
group by statesetbyuserid
order by 'Number of Alerts' DESC


Installed Management Packs

Type - Data Grid

Title - Installed Management Packs
Header Text
Column
Management Pack Name
MPFriendlyName
Version
MPVersion


SELECT MPName, MPFriendlyName, MPVersion, MPIsSealed
FROM ManagementPack WITH(NOLOCK)
ORDER BY MPName