Hi @techresearch7777777 ,
You can try to use below T-SQL to find logins. Below example is to find logins last 7 days. If you want to go back further than 7 days, you change the 7 values below to match your needs.
CREATE PROC usp_GetLoginsListFromLastWeek
AS
BEGIN
SET NOCOUNT ON
DECLARE @ErrorLogCount INT
DECLARE @LastLogDate DATETIME
DECLARE @ErrorLogInfo TABLE (
LogDate DATETIME
,ProcessInfo NVARCHAR (50)
,[Text] NVARCHAR (MAX)
)
DECLARE @EnumErrorLogs TABLE (
[Archive#] INT
,[Date] DATETIME
,LogFileSizeMB INT
)
INSERT INTO @EnumErrorLogs
EXEC sp_enumerrorlogs
SELECT @ErrorLogCount = MIN([Archive#]), @LastLogDate = MAX([Date])
FROM @EnumErrorLogs
WHILE @ErrorLogCount IS NOT NULL
BEGIN
INSERT INTO @ErrorLogInfo
EXEC sp_readerrorlog @ErrorLogCount
SELECT @ErrorLogCount = MIN([Archive#]), @LastLogDate = MAX([Date])
FROM @EnumErrorLogs
WHERE [Archive#] > @ErrorLogCount
AND @LastLogDate > getdate() - 7
END
-- List all last week logins count of attempts
SELECT COUNT (TEXT) AS NumberOfAttempts, TEXT AS Details, MIN(LogDate) as MinLogDate, MAX(LogDate) as MaxLogDate
FROM @ErrorLogInfo
WHERE ProcessInfo = 'Logon'
AND LogDate > getdate() - 7
GROUP BY TEXT
ORDER BY NumberOfAttempts DESC
SET NOCOUNT OFF
END
We execute the procedure:
exec usp_GetLoginsListFromLastWeek
Drop the procedure after getting the information.
DROP PROCEDURE usp_GetLoginsListFromLastWeek;
GO
Please refer to this third blog to get more explain about this query.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".