Avatar of Stanley Lai
Stanley Lai
Flag for Hong Kong asked on

How to extract MS SQL accounts with last login date?

Hi,

Our auditors request us to  create a daily list of all "active" SQL accounts (include all those NT Service, NT Authority, ##MS_Policy together with all accounts via Windows Authentication) with last login date shown.  In case that enabled account never used to login, the last login date should show blank rather than skip it.  May I know how to create such stored procedure so that I can schedule to run it on a daily basis?

Thanks a lot.
Stanley
Windows OSSQL

Avatar of undefined
Last Comment
Stanley Lai

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lcohan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Stanley Lai

ASKER
Hi Icohan,

 

Thanks a lot for your prompt reply.

 

However, after I execute your provided script, I found it only list out all IDs which once login (with last login date).  For those enabled accounts which never login, it will missed out.

 

May I know how to cater for those missing items?

 

Attached is the result after executed your provided script and direct compare with all those enabled accounts as appeared in the SQL server management studio.  All those marked in yellow are missing items.

 

Kindly please help.

 

Cheers

Stanley
IMG_20200123_151927.jpg
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes