Patch My PC Power BI Queries

When running a Power BI report, you are prompted to trust the SQL native queries. Here we provide the queries, and an explanation on their usage.

SQL Queries

Client Info

Collection of information about devices including what version of the operating system they are running, and FQDN. Originally we used to gather this from a different view, however this caused numerous reports of duplicate values for large environments due to maintenance tasks not running quickly enough. Instead we dynamically build the content. We also have to handle duplicates caused by OS caption.

WITH NewestOS AS (
SELECT GS_OS_Data.ResourceID
	, TimeStamp
	, Caption0
FROM v_GS_Operating_System as GS_OS_Data
INNER JOIN (SELECT ResourceID
	, MAX(TimeStamp) as MaxDate
	FROM v_GS_Operating_System
	GROUP BY ResourceID
) MaxFilter on  GS_OS_Data.ResourceID = MaxFilter.ResourceID and MaxFilter.MaxDate = GS_OS_Data.TimeStamp
)
SELECT v_R_System.ResourceID 
  , v_R_System.Name0    
    , v_R_System.Name0 + '.' + v_R_System.Full_Domain_Name0 as Resource_Names0
    , v_R_System.Resource_Domain_OR_Workgr0 AS 'DOMAIN'
    , CASE v_R_System.Client0
            WHEN 1 THEN 'INSTALLED'
            ELSE 'MISSING'
        END AS ClientStatus
    , v_R_System.Client_Version0
    , v_R_System.Last_Logon_Timestamp0
    , CASE NewestOS.Caption0
        WHEN NULL THEN v_R_System.Operating_System_Name_and0
        ELSE NewestOS.Caption0
    END AS OSNAME
    , V_GS_System.SystemRole0
FROM v_R_System
LEFT OUTER JOIN NewestOS on v_R_System.ResourceID = NewestOS.ResourceID
LEFT OUTER JOIN v_GS_System ON v_R_System.ResourceID = v_GS_System.ResourceID
WHERE v_R_System.Operating_System_Name_and0 LIKE '%Microsoft%'

Compliance Info

Collect patch compliance data. Technically the 0 management is not required here, as 0 should never appear in v_Update_ComplianceStatus

We also filter out some information to ensure we are avoiding accidentally capturing software update groups.

SUG Info

This query gathers the names of each software update group, and creates a dummy row, for updates that are not in any software update group. This is done to handle a use case with Power BI.

SUG Relation Map

This builds what we call the relation map, and tracks what updates are a member of what group. This is how we then are able to filter our report by software update groups. This data is used as a connection point in the PowerBI data model to join data together.

Collection Membership

Collections, often represent logical groupings of machines we really care about. As a result, we use this query to build out what machines are a member of what collection so we can allow filtering based on the collection names.

Update Info

While knowing a CI_ID of an update is nice, you typically want more detailed information. This, collects data for things like the URL for information about the update, the date it was released, and more.

Category Info

Some times it really helps to be able to filter a report by the patching vendors. This section gathers who the original author of the patch was.

Last updated

Was this helpful?