SCCM Client Inventory and WSUS Scan state

Here is a view that you can use to see SCCM Client inventory and WSUS scan state information.

CREATE view [dbo].[v_SCCM_Health_Check] as

select distinct a.name0 as 'MachineName'
, a.itemkey
, a.operating_system_name_and0 as 'OperatingSystem'
, os.CSDVersion0 as 'OS_ServicePack'
, a.client0 as 'SCCM_Client'
, a.Client_Version0 as 'SCCM_ClientVersion'
, case when a.User_Name0 like '%\%' then substring(a.User_Name0,charindex('\',a.User_Name0)+ 1,charindex('\',a.User_Name0))
    else a.User_Name0 end AS 'LastLoggedOnUser'
, case when scud.TopConsoleUser0 like '%\%' then substring(scud.TopConsoleUser0,charindex('\',scud.TopConsoleUser0)+ 1,charindex('\',scud.TopConsoleUser0)) 
    else scud.TopConsoleUser0 end as 'MainUser'
, nlp.FullName0 as 'MainUserFullName'
, a.AD_Site_Name0 as 'AD_Site'
, ou.OU
, a.Resource_Domain_OR_Workgr0 as 'Domain'
, e.SiteCode as 'SCCM_Site_Code'
, b.LastHWScan as 'SCCM_LastHWscan'
, c.LastUpdateDate as 'SCCM_LastSWscan'
, Dateadd(hour,(datediff(hour,getutcdate(),getdate())),d.lastscantime) as 'Last_WSUSscan'
, scan.StateName 'WSUSscan_State'
, scan.ErrorStatusID
, scan.ErrorCode
, scan.HexErrorCode
, uagent.version00 'WSUS_AgentVersion'
, d.lastlocation as 'WSUSserver'
, CCMService.State0 as 'SMS_Agent_Host_Service'
, AutoUpdates.State0 as 'Auto_Updates_Service'
from SMS_CEN.dbo.System_DISC a 
left join SMS_CEN.dbo.WorkstationStatus_DATA b
on a.itemkey = b.machineid  
left join SMS_CEN.dbo.SoftwareInventoryStatus c
on a.itemkey = c.clientid  
left join SMS_CEN.dbo.Update_ScanStatus d
on a.itemkey = d.machineid 
left join SMS_CEN.dbo.Windows_Update_Agent__DATA uagent
on a.itemkey = uagent.machineid 
left join SMS_CEN.dbo.Sites_DATA e  
on a.itemkey = e.machineid  
left join dbo.SCCM_Health_Check_DATA f
on a.itemkey = f.machineid 
left join dbo.Operating_System_DATA os
on a.itemkey = os.machineid  
left join
select uss.ResourceID, SN.StateName, uss.LastStatusMessageID&0x0000FFFF as ErrorStatusID,
    isnull(uss.LastErrorCode,0) as ErrorCode,
    dbo.fnConvertBinaryToHexString(convert(VARBINARY(8), isnull(uss.LastErrorCode,0))) as HexErrorCode
 from v_UpdateScanStatus uss
    join v_R_System rsys on rsys.ResourceID = uss.ResourceID and isnull(rsys.Obsolete0,0)<>1
    join v_SoftwareUpdateSource sus on uss.UpdateSource_ID = sus.UpdateSource_ID 
    join v_RA_System_SMSAssignedSites sass on uss.ResourceID = sass.ResourceID
    join v_StateNames sn on sn.TopicType = 501 and 
        sn.StateID = (case when (isnull(uss.LastScanState, 0)=0 and Left(isnull(rsys.Client_Version0, '4.0'), 1)<'4') then 7 else isnull(uss.LastScanState, 0) end)
) scan
on a.itemkey = scan.ResourceID  
on a.itemkey = scud.resourceID
left join dbo.v_GS_NETWORK_LOGIN_PROFILE nlp
on nlp.name0 = scud.TopConsoleUser0 and nlp.resourceID = scud.resourceid
left join
    select machineid, State0
    from     dbo.Services_DATA
    where name0 = 'ccmexec'
    ) CCMService
on a.itemkey = CCMService.machineid
left join
    select machineid, State0
    from     dbo.Services_DATA
    where name0 = 'wuauserv'
    ) AutoUpdates
on a.itemkey = AutoUpdates.machineid
left join
    select itemKey, max(system_ou_name0) as 'OU'
    from dbo.System_System_OU_Name_ARR
    group by itemkey
    ) OU
on a.itemkey = ou.itemkey

.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s