【问题标题】:Extract data from Windows Server Update Services (WSUS) using SQL query使用 SQL 查询从 Windows Server Update Services (WSUS) 中提取数据
【发布时间】:2015-04-18 18:37:10
【问题描述】:

我从未使用过 WSUS,所以我真的不知道如何获取正确的数据。目标是创建一个包含三列的表:计算机组、计算机名称、需要更新的数量

我在这里发现:Microsoft Developer Network WSUS 使用 SQL 服务器存储我需要的数据,我可以通过 \.\pipe\MSSQL$MICROSOFT##SSEE\sql\query 连接到它。我更喜欢这种方法,而不是 PowerShell 或其他方法,因为最后我需要在其他 sqlserver 中使用这些数据。

有人可以帮我提取所需信息的 SQL 查询吗?我在数据库或 PUBLIC_VIEWs 中看不到任何熟悉的东西。非常感谢。

【问题讨论】:

    标签: tsql windows-update


    【解决方案1】:

    在此处使用 SUSDB 是一个包含您请求的列的最小版本:

    Select tg.Name as ComputerGroup, ct.FullDomainName as ComputerName, Count(*) As Needed
    From tbComputerTarget AS ct 
    Join tbComputerTargetDetail ctd on ctd.TargetId = ct.TargetId
    Join tbTargetInTargetGroup tgct on tgct.TargetId = ct.TargetId
    Join tbTargetGroup tg on tg.TargetGroupId = tgct.TargetGroupId
    Join tbUpdateStatusPerComputer as s on ct.TargetID = s.TargetID And SummarizationState In(2,3,6)
    Group By tg.Name, ct.FullDomainName;
    

    【讨论】:

      【解决方案2】:

      使用 SUSDB,以下是计算机的摘要,其中包含您要求的更多列:

      With cteUpdateInstallationInfo As(
       SELECT u.UpdateID
       , ct.ComputerID 
       , (CASE WHEN usc.SummarizationState IS NULL OR usc.SummarizationState = 1 THEN (CASE WHEN ISNULL(u.LastUndeclinedTime, u.ImportedTime) < ct.EffectiveLastDetectionTime THEN 1 ELSE 0 END) ELSE usc.SummarizationState END) AS State
        FROM       dbo.tbUpdate AS u 
        JOIN       dbo.tbRevision AS r ON u.LocalUpdateID = r.LocalUpdateID And r.IsLatestRevision = 1
        JOIN       dbo.tbProperty AS p ON r.RevisionID = p.RevisionID And p.ExplicitlyDeployable = 1
        CROSS JOIN dbo.tbComputerTarget AS ct 
        LEFT JOIN  dbo.tbUpdateStatusPerComputer AS usc ON u.LocalUpdateID = usc.LocalUpdateID AND ct.TargetID = usc.TargetID
        WHERE u.IsHidden = 0
      ), Summary as(
        Select ComputerId
        , Count(*)  as Total
        , Sum(case When State = 0 Then 1 else 0 end)       as NoStatus
        , Sum(case When State = 1 Then 1 else 0 end)       as NotApp
        , Sum(case When State In(2,3,6) Then 1 else 0 end) as Needed
        , Sum(case When State = 4 Then 1 else 0 end)       as Installed
        , Sum(case When State = 5 Then 1 else 0 end)       as Failed
        From cteUpdateInstallationInfo
        Group by ComputerId
      ), TimeZone as (
       Select DATEDIFF(mi, GetUtcDate(), GetDate()) as TimeZoneMinutes
      )
      Select ct.ComputerId
      , ct.FullDomainName 
      , ct.IPAddress
      , tg.Name as TargetGroupName
      , Total, NoStatus, NotApp, Needed, Failed, Installed
      , Dateadd(mi, TimeZoneMinutes, ct.EffectiveLastDetectionTime) As LastDetectLocalTime
      , Dateadd(mi, TimeZoneMinutes, ct.LastReportedStatusTime) as LastReportLocalTime
      , Dateadd(mi, TimeZoneMinutes, ct.LastSyncTime) As LastContactLocalTime
      , LastSyncResult    
      
      , Dateadd(mi, TimeZoneMinutes, ct.LastReportedRebootTime) As LastRebootLocalTime
      , Dateadd(mi, TimeZoneMinutes, ct.LastInventoryTime) As LastInventoryLocalTime
      , Dateadd(mi, TimeZoneMinutes, ct.LastNameChangeTime) As LastNameChangeLocalTime
      --, IsRegistered
      --, OSMajorVersion, OSMinorVersion, OSBuildNumber, OSServicePackMajorNumber,OSServicePackMinorNumber
      , OSLocale
      , ComputerMake
      , ComputerModel
      , BiosVersion
      , BiosName
      , BiosReleaseDate
      , ProcessorArchitecture
      --, LastStatusRollupTime    LastReceivedStatusRollupNumber  LastSentStatusRollupNumber
      --, SamplingValue, CreatedTime, SuiteMask, OldProductType, NewProductType, SystemMetrics
      , ClientVersion
      --, TargetGroupMembershipChanged
      , OSFamily
      , OSDescription
      , OEM
      , DeviceType
      , FirmwareVersion
      , MobileOperator    
      From Summary as s 
      Join TimeZone as tz on 1=1
      JOIN dbo.tbComputerTarget AS ct on ct.ComputerID = s.ComputerId
      Join tbComputerTargetDetail ctd on ctd.TargetId = ct.TargetId
      Join tbTargetInTargetGroup tgct on tgct.TargetId = ct.TargetId
      Join tbTargetGroup tg on tg.TargetGroupId = tgct.TargetGroupId
      

      这里还有一个总结更新

      With Summary as(
        Select UpdateId
        , Count(*)  as Total
        , Sum(case When State = 0 Then 1 else 0 end)     as NoStatus
        , Sum(case When State = 1 Then 1 else 0 end)     as NotApp
        , Sum(case When State In(2,3,6) Then 1 else 0 end) as Needed
        , Sum(case When State = 4 Then 1 else 0 end)     as Installed
        , Sum(case When State = 5 Then 1 else 0 end)     as Failed
        From PUBLIC_VIEWS.vUpdateInstallationInfo
        Group BY UpdateId
      ), TimeZone as (
       Select DATEDIFF(mi, GetUtcDate(), GetDate()) as TimeZoneMinutes
      )
      Select s.UpdateId
      , u.IsDeclined
      , u.PublicationState
      , u.DefaultTitle as Title
      , u.KnowledgebaseArticle as KBArticle
      , Total, NoStatus, NotApp, Needed, Failed, Installed 
      , Dateadd(mi, TimeZoneMinutes, u.CreationDate) As ReleaseLocalTime
      , Dateadd(mi, TimeZoneMinutes, u.ArrivalDate) As ArrivalLocalTime
      From summary as s
      Join TimeZone as tz on 1=1
      Join PUBLIC_VIEWS.vUpdate as u on u.UpdateID = s.UpdateId
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多