Cria e Linked server com o AD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
exec sp_addlinkedserver 'adsi', '', 'ADSDSOObject', '' GO -- Change 'adsi' to the desired name of the linked server -- Change 'sqlUser' to the username of local sql server user -- Change 'domainName\userName' to a domain account -- (the format can be 'domainName\userName' or 'userName@domainName') -- Change 'domainUserPassword' to the password of the domain account exec sp_addlinkedsrvlogin 'adsi', false, 'siscobrape', 'Dominio\usuario', 'senha' go select * from openquery(adsi, ' select dNSHostname, name,homeDrive, userPrincipalName, givenName, sn, sAMAccountName, displayName, mail, telephoneNumber, mobile, physicalDeliveryOfficeName, department, division from ''LDAP://SVRDOMINIO'' where objectCategory = ''Person'' and objectClass = ''user'' ') WHERE displayname LIKE '%victor%' |