Below script will only list the DB's where guest user is enabled.
create table #guest_users
(
ServerName nvarchar(50),
DBName nvarchar(200),
name sysname,
Status nvarchar(50)
)
EXEC sp_MSforeachdb
'USE [?];
Insert into #guest_users
SELECT
@@Servername AS ServerName,
DB_NAME() AS DBName,
name,
case hasdbaccess when 1 then
''Enabled'' else ''Disabled'' end AS Status
FROM sysusers where name like
''guest'' AND hasdbaccess = 1;'
Select * from #guest_users
drop table #guest_users
--- Below script will list the DB's where guest user is enabled/disabled with value
CREATE TABLE #guest_users
(
ServerName nvarchar(50),
DBName nvarchar(200),
name sysname,
Status nvarchar(50)
)
EXEC sp_MSforeachdb
'USE [?];
Insert into #guest_users
SELECT @@Servername AS ServerName,
DB_NAME() AS DBName,
name,
case hasdbaccess when 1 then ''Enabled'' else ''Disabled'' end AS Status
FROM sysusers
where name like ''guest'';'
SELECT * FROM #guest_users
DROP TABLE #guest_users
No comments:
Post a Comment