Search code examples
sql-servert-sqlwindows-update

Query WSUS Database For Required Updates Per Server


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/


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