Insert into Active Directory Using SQL

Micah Holmes 121 Reputation points
2021-02-24T21:09:04.477+00:00

I have a User Account that's created using our ERP. Once created the SQL does some stuff to the record and spits out some attributes that later get updated in AD using a Batch job. I want to update the AD records in SQL and avoid he batch job all together to further optimize. Alternative is to build an API and perform the AD update in there using .Net code. However, it makes more sense to us to just update AD in SQL since SQL will already have the attribute data for the record we need to inject. So far not been able to find anything on how to write to AD from SQL. We already can read from AD to SQL. So there must be a way to write to AD from SQL. I assume we just need a connection or something? Anyone have samples or video tuts etc? Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,367 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,246 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 107.2K Reputation points
    2021-02-24T22:55:03.197+00:00

    Nope. If you look at the documentation for the OLE DB provider for Active Directory at https://learn.microsoft.com/en-us/sql/ado/guide/appendixes/microsoft-ole-db-provider-for-microsoft-active-directory-service?view=sql-server-ver15, you will find that it does not support write operations.

    Well, if you are going to do in .NET, you could do that from a CLR procedure, but if you are not using the CLR already, I am not sure that it is worth the complexity.

    0 comments No comments

  2. AmeliaGu-MSFT 13,971 Reputation points Microsoft Vendor
    2021-02-25T06:25:42.557+00:00

    Hi MicahHolmes-1650,

    Agree with Erland. You can use CLR stored procedure or CLR function with Directory Services object to update the Active Directory.
    Please refer to the following threads which might help:
    Update users in Active Directory form SQL query update
    Syncing Active Directory with my Application
    How to register System.DirectoryServices for use in SQL CLR User Functions

    Best Regards,
    Amelia

    0 comments No comments