Find computers with no active users.

This query will find all computers in SCCM that have had not user logon within the last 30 days.

declare @Now as datetime
set @Now = getdate()

;with MINLCU as
(
Select
SCU.ResourceID as ‘ResourceID’,
min(SCU.LastConsoleUse0) as ‘LastConsoleUse0’
From
dbo.v_GS_SYSTEM_CONSOLE_USER SCU
Group by
SCU.ResourceID
)

select
RV.Netbios_Name0,
SCU.SystemConsoleUser0,
SCU.LastConsoleUse0,
SCU.NumberOfConsoleLogons0
from
dbo.v_R_System_Valid RV
Join dbo.v_GS_SYSTEM_CONSOLE_USER SCU on RV.ResourceID = SCU.ResourceID
join MINLCU on RV.ResourceID = MINLCU.ResourceID
Where
datediff(dd,MINLCU.LastConsoleUse0, @Now) >30
order by
RV.Netbios_Name0,
SCU.LastConsoleUse0 DESC

Leave a Reply

Your email address will not be published. Required fields are marked *