Cleaning up specific domain logins on about 50 servers and therefore the users There is a specific need to clean up logins from the SQL Servers after migration from one domain say abc to new domain foo.

After migration as we still have those old logins and users under naming of abc\login1, abc\login2... and so on.

How can I perform this clean up to delete all the logins from the server, which has Windows logins say with domain abc\.. and within same script to delete all the related users within the instance for all databases.

I've searched the link SQL Server script to delete accounts no longer in Active Directory but it does not help in deleting users. 

Note: These are just Windows logins and not part of any AD group. Just want to drop logins and the db users associated with it. Other domain AD users have been taken care by our AD and wintel team and users are all set. Just doing the clean up here.
I have had a similar task recently. My solution:


Create a temporary stored procedure #sp_helplogins which is a copy of sp_helplogins but returns only the second rowset.
Get logins to delete (in my case by using sp_validatelogins)  

DECLARE @Login  sysname, @SQL   NVARCHAR(4000)

CREATE TABLE #BadLogins
(
    [SID]       varbinary(85)
    ,NTlogin    sysname
)

CREATE TABLE #BadUsers
(
    LoginName       VARCHAR(100)
    ,DBName         VARCHAR(100)
    ,UserName       VARCHAR(100)
    ,UserOrAlias    VARCHAR(100)
    ,IsDeleted      INT
)

INSERT #BadLogins
EXEC sp_validatelogins

Get associated users

DECLARE myCursor CURSOR READ_ONLY
FOR
SELECT DISTINCT NTlogin
FROM #BadLogins

OPEN myCursor

FETCH NEXT FROM myCursor INTO @Login

WHILE @@FETCH_STATUS = 0 BEGIN

INSERT #BadUsers
EXEC #sp_helplogins @Login

FETCH NEXT FROM myCursor INTO @Login

END

CLOSE myCursor
DEALLOCATE myCursor

Drop the users

DELETE #BadUsers
WHERE DATABASEPROPERTYEX(DBName, 'Updateability') != 'READ_WRITE'

WHILE EXISTS ( SELECT 1 FROM #BadUsers WHERE IsDeleted = 0 AND UserOrAlias = 'User' ) BEGIN

SELECT TOP 1 @SQL = 'USE ' + DBName + '
DROP USER ' + QUOTENAME(UserName)
FROM #BadUsers
WHERE IsDeleted = 0
    AND UserOrAlias = 'User'
ORDER BY UserName,DBName

EXEC sp_executesql @SQL
--SELECT @SQL

UPDATE u
SET IsDeleted = 1
FROM #BadUsers u
    JOIN (
        SELECT TOP 1 DBName, UserName
        FROM #BadUsers
        WHERE IsDeleted = 0
            AND UserOrAlias = 'User'
        ORDER BY UserName,DBName
    ) d ON d.DBName = u.DBName AND d.UserName = u.UserName
WHERE IsDeleted = 0

END



Notice that I don't handle a case when a user have an owned schema so the users won't be deleted by my script.