Created
December 9, 2016 09:49
-
-
Save xrisdoc/b39189061f3bcfd10251b93d24440b81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT (SELECT SUBSTRING( | |
(SELECT ('; ' + Username + '') FROM | |
(SELECT AD.sAMAccountName as Username | |
FROM OPENQUERY(ADSI, 'SELECT sAMAccountName, displayName, userPrincipalName, userAccountControl, company | |
FROM ''LDAP://myserver/OU=SBSUsers,OU=Users,OU=MyBusiness,DC=my-domain,DC=co,DC=uk'' | |
WHERE objectClass = ''Person''' | |
) AD | |
WHERE AD.userPrincipalName Is NOT Null | |
AND AD.sAMAccountName Is Not Null | |
AND AD.userAccountControl NOT IN (512, 546, 514, 66050) | |
AND AD.company Is NOT Null) x | |
ORDER BY x.Username ASC | |
FOR XML PATH('')) | |
,3,200000)) AS Usernames; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment