I created a vbs that looks like this:
strComputer = "." Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOS in colOperatingSystems dtmBootup = objOS.LastBootUpTime dtmLastBootupTime = WMIDateStringToDate(dtmBootup) dtmSystemUptimeH = DateDiff("h", dtmLastBootUpTime, Now) dtmSystemUptimeS = DateDiff("s", dtmLastBootUpTime, Now) dtmSystemUptimeM = round(dtmSystemUptimeS/60,0) Wscript.Echo dtmSystemUptimeH Next Function WMIDateStringToDate(dtmBootup) WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _ Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _ & " " & Mid (dtmBootup, 9, 2) & ":" & _ Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _ 13, 2)) End Function
Which reports how many hours since the last reboot. I created a software inventory item called "CI - Last Reboot" and attached the vbs to the inventory. I then used the File sync under distribution to sync the vbs to all windows pc's to a folder called c:\admin\scripts and added a shell command to the software inventory item that looks like this:
ShellCommandtextreturn(cmd.exe /c cscript //nologo "c:\admin\scripts\uptime.vbs")
That then populates the Custom inventory field with only a number... which is in hours format.
Once that is in place a smart label can query the number and you can easily say more than x amount of hours ect. And if you want then can create a "Nag" alert for users that are part of a label that indicates no reboot in x amount of time. (this all takes 2-3 inventories before the field begins to populate)
I also used a similar setup for my tiered patching which goes in place next week if there is any interest in that let me know, I'd be happy to share the scripts and config for it.
It will label computers that haven't rebooted or shutdown greater than 7 days.
select MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME,
UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS
from ORG1.MACHINE
LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 1
where (NOT OS_NAME LIKE '%server%') AND (LAST_REBOOT < DATE_SUB(CURDATE(), INTERVAL 7 DAY) OR LAST_SHUTDOWN < DATE_SUB(CURDATE(), INTERVAL 7 DAY)) - flip1001 11 years ago
New smart label:
SELECT MACHINE.*, C.CLIENT_CONNECTED, UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_TIME,
UNIX_TIMESTAMP(LAST_SYNC) as LAST_SYNC_SECONDS
FROM ORG1.MACHINE
LEFT JOIN KBSYS.KUID_ORGANIZATION O ON O.KUID=MACHINE.KUID LEFT JOIN KBSYS.SMMP_CONNECTION C ON C.KUID = MACHINE.KUID AND O.ORGANIZATION_ID = 1
WHERE (NOT OS_NAME LIKE '%server%') AND (LAST_REBOOT < DATE_SUB(CURDATE(), INTERVAL 7 Day)) AND (LAST_SHUTDOWN < DATE_SUB(CURDATE(), INTERVAL 7 Day)) AND NOT (LAST_REBOOT = 'empty') AND NOT (LAST_REBOOT = '') AND NOT (LAST_SHUTDOWN = 'empty') AND NOT (LAST_SHUTDOWN = '')
Mysql workbench query to find the problematic machines not reporting last reboot/shutdown properly:
SELECT MACHINE.*
FROM ORG1.MACHINE
WHERE (LAST_REBOOT = 'empty') OR
(LAST_REBOOT = '') OR
(LAST_SHUTDOWN = 'empty') OR
(LAST_SHUTDOWN = '') OR
(NOT LAST_REBOOT = LAST_SHUTDOWN) - flip1001 11 years ago