查询WSUS数据库以获取每服务器所需的更新

时间:2014-02-27 05:20:22

标签: sql-server tsql windows-update

我远程搜索互联网,寻找一种查询WSUS数据库的方法,以查看需要在服务器上安装的更新数量。我在下面的博客上找到了部分答案,但是这个答案将假设如果更新正在等待批准,那么服务器仍然需要它(WSUS也会在他们的UI中假定这一点)。

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

2 个答案:

答案 0 :(得分:3)

我希望这个解决方案对其他人有用。

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

答案 1 :(得分:1)

我可以过滤更新名称

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%'