• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2086
  • Last Modified:

SCCM 2007 - Find Date of Last Patch Installed on the Server

I am looking for the best way to collect the date of the last patch successfully installed to the server, which indicates when the server was last patched.

In Powershell, we have used the following script to accomplish this task:

Foreach ($Server in $colServers)
}    	{
	    Get-HotFix -ComputerName $Server.Name | `
	    Where {$_.InstalledOn} | `
	    Sort InstalledOn -Descending | `
	    Select CSname, @{Name = "Installed"; Expression = {"{0:M/dd/yyyy}" -f [datetime]$_.InstalledOn.Tostring()}} -First 1
        Write-Host ($Server.Name + ":  " + $Error[0])

Open in new window

I need to collect this information from the SCCM database using a SQL statement.  One query I looked at as a possibility was the following:

SELECT DISTINCT v_R_System.Name0 AS 'Machine Name', 

      v_gs_patchstatusEx.ID AS 'Bulletin ID#', 

      v_gs_patchstatusEx.QNumbers as 'QNumber', 

      v_gs_patchstatusEx.Title as 'Title', 

      v_gs_patchstatusEx.LastStateName as 'Last State',  

      v_gs_patchstatusEx.LastStatusMessageIDName as 'Last Status', 

      v_gs_patchstatusEx.LastStatusTime as 'Last Status Time'
FROM v_gs_patchstatusEx 

INNER JOIN v_R_System on v_R_System.ResourceID = v_gs_patchstatusEx.ResourceID 

INNER JOIN v_ClientCollectionMembers on v_ClientCollectionMembers.ResourceID = v_R_System.ResourceID
INNER JOIN v_UpdateComplianceStatus on v_UpdateComplianceStatus.ResourceID = v_R_System.ResourceID
WHERE (v_gs_patchstatusEx.id <> 'None') AND 

        (v_gs_patchstatusEx.LastStateName = 'Install Verified') AND 
        (DATEDIFF(hh,v_GS_PatchStatusEx.LastStatusTime,Getdate())<=48 )AND
        (v_UpdateComplianceStatus.Status=2) AND 

ORDER BY v_gs_patchstatusEx.LastStatusTime, v_gs_patchstatusEx.ID DESC

Open in new window

However, I need to modify it to only collect the date of the most recently installed patch.  I think the Powershell script above targets the Win32_QuickFixEngineering WMI class and I would like to continue using this same functionality in a SQL statement if it can be done.

The most important thing is accuracy.  I must have the date of the latest patch successfully installed on the server.
  • 2
1 Solution
Leon TaljaardSystem Center Specialist - ArchitectureCommented:

Not sure if something like this might help ?

select b.Name,b.CollectionID,a.DisplayName0,
CONVERT(VARCHAR, DATEADD(hh, 2, a.InstallDate0),103) as 'Install Date'
from dbo.v_Add_Remove_Programs a join dbo.v_FullCollectionMembership b on a.ResourceID = b.ResourceID
where b.Name like 'Computer Name'
isd503Author Commented:
We are making some changes to SCCM to be able to collect accurate SQL and Microsoft patch data.
isd503Author Commented:
I could not find another way to get this done accurately.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now