Finding machines not compliant with a specific security bulletin
Originally posted on TechNet.
I read Marc’s BROKEN - post about Compliance Reporting and it was similar to a problem I deal with in my job. Part of my job is to run Update Management on one of the domains consisting of around 12,000 managed computers at Microsoft using WSUS. We do this in order to validate WSUS (and similar products) in an environment with real users. Another group at Microsoft audits my compliance, and often request a list of non-compliant machines for specific security bulletins. I have adapted Marc’s SQL script to do just that.
I ran into one issue, Marc’s SQL script will blocks clients from scanning while it runs. Since the script can take a long time to execute on larger data sets, I decided to allow SQL to read dirty data and unblock my clients (SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
.).
I hope you find this useful.
Travis Plunk
Software Design Engineer in Test II, WSUS
-- Find computers within a target group that need a security bulletin
USE SUSDB
go
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO
DECLARE @TargetGroup nvarchar(30)
DECLARE @Bulletin nvarchar(9)
SELECT @TargetGroup = 'All Computers'
SELECT @Bulletin = 'MS08-030'
-- Find the computers not compliant for each security bulletin in the given @TargetGroup
-- where the approved occured between @Days and @DaysEnd days ago
SELECT ct.Name,@Bulletin as Bulletin,ct.LastReportedStatusTime
FROM PUBLIC_VIEWS.vComputerGroupMembership as cgm INNER JOIN
as ct ON
PUBLIC_VIEWS.vComputerTarget = ct.ComputerTargetId INNER JOIN
cgm.ComputerTargetId as ctg ON
PUBLIC_VIEWS.vComputerTargetGroup = ctg.ComputerTargetGroupId
cgm.ComputerTargetGroupId WHERE (ctg.Name = @TargetGroup)
-- And only select those for which an update is approved for install, the
-- computer status for that update is either 2 (not installed), 3 (downloaded),
-- 5 (failed), or 6 (installed pending reboot), and
-- the update bulletin is the one provided.
AND EXISTS
SELECT 1
(FROM PUBLIC_VIEWS.vUpdateEffectiveApprovalPerComputer as ueapc INNER JOIN
as ua ON
PUBLIC_VIEWS.vUpdateApproval = ueapc.UpdateApprovalId INNER JOIN
ua.UpdateApprovalId ON
PUBLIC_VIEWS.vUpdateInstallationInfoBasic uiib = ct.ComputerTargetId AND
uiib.ComputerTargetId = uiib.UpdateId
ua.UpdateId inner join PUBLIC_VIEWS.vUpdate as u on ua.updateid=u.updateId
WHERE (ueapc.ComputerTargetId = ct.ComputerTargetId) AND
= 'Install') AND (uiib.State IN (2, 3, 5, 6)) AND u.securityBulletin is not null and u.securityBulletin=@Bulletin ) (ua.Action