This might be almost close. You'd have to add in whatever it is you mean by lastlogontimestamp (that can mean different things to different people, I've replaced that with LastScanTime for updates--to me that seems more relevant since this is about scanning for patches.)
This would be...
- All Computers, with their last scan-for-updates time and state of that scan
- The latest Cumulative Updates for Windows
- The latest known results for all resourceids..for those specific CUs in #2--BUT only if those resourceids are applicable for those CUs. i.e., you don't really care that Windows 10 1809 is compliant-by-default for Windows 10 1709's latest Cumulative Update, do you? all you care about is if it's compliant or not for the 1809 Cumulative Update, the one it actually deserves; or at least... that's all I would care about.
End result...
1 line per machine.
if that machine hasn't bothered to mention whether or not it's compliant or not for the latest CU; they will have Null in the columns for Title, Status, TextStatus, and DateRevised. This will likely happen easily/frequently just after the latest is released and you've updated your environment.
If however, it's days later; maybe you'd want to know that some boxes are not scanning/reporting. Up to you to figure out why not. (although usually it's probably just that those machines are offline... but maybe they are messed up in some way; and you need to fix 'em)
;with TheComputers as (
select s1.netbios_name0 as 'ComputerName', s1.Resourceid, uss.LastScanTime, uss.lastscanstate
from v_r_system_valid s1
left join v_UpdateScanStatus uss on uss.resourceid=s1.resourceid
)
,TheOSUpdates as (
select ui.Title, ui.ci_id, ui.DateRevised
from v_updateinfo ui
where ui.title like '%cumulative Update for Windows%' and ui.IsLatest=1
)
,TheResultsForThoseUpdates as (Select ResourceID, TheOsUpdates.Title, TheOSUpdates.DateRevised, Status
from v_Update_ComplianceStatus ucs
join TheOSUpdates on TheOSUpdates.ci_id = ucs.ci_id)
Select TheComputers.ComputerName
,TheComputers.LastScanState,TheComputers.LastScanTime
,TheResultsForThoseUpdates.Title
,TheResultsForThoseUpdates.Status
,Case
when TheResultsForThoseUpdates.Status=3 then 'Installed'
when TheResultsForThoseUpdates.Status=2 then 'Required'
Else cast(TheResultsForThoseUpdates.Status as varchar) end as 'TextStatus'
,TheResultsForThoseUpdates.DateRevised
from TheComputers
Left Join TheResultsForThoseUpdates on TheResultsForThoseUpdates.Resourceid=TheComputers.Resourceid