I need to query AD to determine if a users account is disabled.
Using a similar query used in the answers here
SELECT *
FROM OPENQUERY(ADSI, 'SELECT sAMAccountName
FROM ''LDAP://DC=MyDC,DC=com,DC=uk''
WHERE objectCategory = ''Person''
AND objectClass = ''user'')
I believe to determine if an account is disabled I have to use the userAccountControl field somehow. I've tried several things but they don't seem to be working:
WHERE userAccountControl & 2 <> 0