Question

I searched the internet far and wide looking for a way to query the WSUS database to view the number of updates that need to be installed on a server. I found a partial answer on the following blog, but this answer will assume if the update is pending approval it is still required by a server (WSUS assumes this in their UI as well).

http://theboywonder.co.uk/2010/11/04/sql-query-for-wsus-3-needed-updates/

Was it helpful?

Solution

I hope this solution is useful for others.

SELECT left(tbComputerTarget.FullDomainName,30) as [Machine Name]
           ,count(tbComputerTarget.FullDomainName) as [# of Missing patches]
           ,tbComputerTarget.LastSyncTime as [Last Sync Time]
FROM tbUpdateStatusPerComputer INNER JOIN tbComputerTarget ON tbUpdateStatusPerComputer.TargetID =          
            tbComputerTarget.TargetID
WHERE (NOT (tbUpdateStatusPerComputer.SummarizationState IN (’1′, ’4′))) AND
            tbUpdateStatusPerComputer.LocalUpdateID IN (SELECT LocalUpdateID FROM dbo.tbUpdate WHERE UpdateID IN        
            (SELECT UpdateID FROM PUBLIC_VIEWS.vUpdateApproval WHERE Action=’Install’))
GROUP BY tbComputerTarget.FullDomainName, tbComputerTarget.LastSyncTime
ORDER BY COUNT(*) DESC

OTHER TIPS

i can filter for the update name

SELECT C.FULLDOMAINNAME AS COMPUTADOR,VU.DEFAULTTITLE AS ATUALIZAÇÃO, 
       'STATUS' = CASE 
       WHEN UP.SummarizationState = 1 THEN 'NÃO INSTALADO' 
       WHEN UP.SummarizationState = 2 THEN 'NÃO INSTALADO'  
       WHEN UP.SummarizationState = 3 THEN 'INSTALANDO'
       WHEN UP.SummarizationState = 4 THEN 'INSTALADO'
       WHEN UP.SummarizationState = 5 THEN 'FALHOU'
       END

FROM TBCOMPUTERTARGET C
INNER JOIN tbUpdateStatusPerComputer UP ON C.TargetID = UP.TargetID
INNER JOIN tbUpdate U ON UP.LocalUpdateID = U.LocalUpdateID
INNER JOIN [PUBLIC_VIEWS].[vUpdate] VU ON U.UpdateID = VU.UpdateId
WHERE VU.DefaultTitle LIKE 'WINDOWS Internet Explorer 9 for Windows 7' 
        OR VU.DefaultTitle LIKE'Update for Microsoft Office 2010%'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top