Quantcast
Channel: Recent Edits
Viewing all articles
Browse latest Browse all 12198

Get all orphaned users from all databases with database name in result set

$
0
0
The tough part was to get the DB name in the result set.  Then, it hit me... do this: $0$0 $0 $0 $0CREATE TABLE #temporphans(UserName Varchar(100), UserSID Varchar(100), dbName varchar(100) null)$0 $0GO$0 $0$0 $0 $0EXEC sp_MSforeachdb @command1 ='$0 $0USE [?]$0 $0INSERT INTO #temporphans (UserName, UserSID)$0 $0$0 $0 $0EXEC [sp_change_users_login] @Action=''Report'';$0 $0$0 $0 $0UPDATE #temporphans SET dbName = ''?'' WHERE dbName IS NULL;$0 $0'$0 $0$0 $0 $0SELECT dbName,UserN

Viewing all articles
Browse latest Browse all 12198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>