t-sql query that queries Active Directory for list of users
Hi experts,
I'm using SQL Server 2019.
I need to create a SQL Server Stored Procedure that queries Active Directory.
Query 1
Windows Powershell query - Get Active Directory users whose password will expire in 15 days.
At this link I saw this query to for a Powershell Script that queries Active Directory and gets Active Directory users whose password will expire in 15 days.
I get this, which is the a list of users whose password will expired in 15 days or less.
So this powershell query returns the result I need. But I need to query Active Directory from a SQL Stored Procedure.
Query 2
So to learn how to query active directory from a sql server query. I looked at this reference which has the information on how to do it.
Step 1: Create Linked Server
Step 2: In the SQL query use LDAp information
After i created a linked server with the script in the link aboei, i then ran this query. But in my query that I ran, i replaced contoso with my domain ino.
SQL Server Query
SELECT * FROM OpenQuery ( ADSI, 'SELECT displayName, telephoneNumber, mail, mobile, facsimileTelephoneNumber FROM ''LDAP://Contoso.com/OU=Users,DC=Contoso,DC=com'' WHERE objectClass = ''User'' ') AS tblADSIORDER BY displayname
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.