SQLTeam.com | Weblogs | Forums

How to drop a set of users


#1

Hi,

I am looking for a way to drop a set of users who belong to the same domain.

The solution I found is something like this:

SELECT * FROM OpenQuery (
ADSI,
'SELECT * FROM ''LDAP://DOMAIN.com/OU=Players,DC=DOMAIN,DC=com''
WHERE objectClass = ''User''
') AS tblADSI
ORDORDER BY displayname

Is there another way?

I am thinking along the line of combining this two

Drop user [myDomain\userX]

and

Select * from sys.database_principals where name like 'myDomain%'

But how?

I appreciate any help!


#2

This will print out the commands that you can then copy/paste/F5: select 'drop user [' + name + ']' from sys.database_principals where name like 'myDomain%'


#3

I knew the copy/paste each user way, or maybe dynamic sql to loop through.

Just wondering if there is a more elegant way.


#4

Isn't it a one-time task? I don't spend time making things elegant if it's one-time and already easy.