T SQL to AD: update record in AD From SQL

Micah Holmes 126 Reputation points
2021-02-25T19:03:49.163+00:00

I posted a question the other day about this but cant find it. Amway, we have a job that runs and updates our AD with SQL attributes for new users only. This job is not the best, it updates all records in AD rather then only the new ones. Anyway, I want to update only the new records from SQL into AD. How do you update AD from SQL? Video tut would be helpful. If CLR please provide video link or sample thanks

SQL Server | Other
{count} vote

4 answers

Sort by: Most helpful
  1. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2021-02-26T07:48:29.15+00:00

    Hi @Micah Holmes ,

    Suggest you read the example that using powershell to create AD users from SQL Serve. Please refer to the blog Sync Active Directory users with a SQL database to get more information. Hope this could help you.


    If the response is helpful, please click "Accept Answer" and upvote it, thank you.

    1 person found this answer helpful.
    0 comments No comments

  2. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2021-02-25T22:28:32.963+00:00

    I did reply to you original post (or least to a question on how to update the AS from SQL Server) and noted that you cannot do this over a linked server.

    I did also say that the CLR is an option, but given the complexity and red tape, I only see it as an option, if you are already using the CLR.

    I think Tom's suggestion to use PowerShell is the best one.

    If you really want to do it in the CLR, there are two things you need to learn:

    1. How to write a CLR procedure.
    2. How to access the AD through the CLR.

    I have a sample of a CLR procedure here: http://www.sommarskog.se/share_data.html#CLR but there are better tutorials out there.

    As for accessing the AD from CLR, you will need to inquire with a suitable tag in your post, and not an SQL Server tag.

    0 comments No comments

  3. Micah Holmes 126 Reputation points
    2021-02-25T23:19:46.887+00:00

    Can i do it using code? Like from an API? I see the exe option

    0 comments No comments

  4. Micah Holmes 126 Reputation points
    2021-02-25T23:28:10.42+00:00

    Ok read a little more on this topic. Can I call Powershell from SQL to execute a script? I'm not a powershell guy so I dont know. I'm a c# guy. Just trying to understand options and best option to update AD. Thanks


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.