When you have an SCCM environment where you deploy Software Updates, but a restart is not enforced on devices you may want to see which devices have not restarted in a certain amount of days. This query will give you a list of the devices with a count of the amount of days.
In this query I have some extra fields for the full name of the user as well as the email address. I use this information to contact these specific users by exporting the results to a spreadsheet and copying all the email addresses into Outlook. If you would like to use these other fields you need to have your Active Directory User Discovery extended.
SELECT SYS.Name0 as [Computer Name], SYS.User_Name0 as [User Name], USR.Full_User_Name0 as [Full Name],
USR.mail0 as [Email Address], Convert(VarChar(10), os.LastBootUpTime0) [Last Restart Date],
OS.lastBootUpTime0 as [Last Restart], DATEDIFF(dd, LastBootUpTime0, GETDATE()) AS [Days Since Last Restart]
FROM v_R_System SYS
JOIN v_Gs_Operating_System OS on SYS.ResourceID = OS.ResourceID
LEFT JOIN v_R_User USR on SYS.User_Name0 = USR.User_Name0
WHERE SYS.Operating_System_Name_and0 like ‘%workstation%’
AND (DATEDIFF(dd, LastBootUpTime0, GETDATE())) >= 7
ORDER BY [Days Since Last Restart] DESC