Active Directory on premise create/delete users using API

Viewed 2766

Hello I am new to Active Directory on premise and my problem is to create user using API. I searched about this, but did not found any documentation. One thing i found is AD Connect but by documentation didn't get any clue. Can any one please let me know is this possible or i'm doing any mistake?

1 Answers

Yes, you can! The link provided by rickvdbosch will get you far.

  1. First, you need to add a using System.DirectoryServices.AccountManagement; statement to your file and possibly a reference to the System.DirectoryServices.AccountManagement assembly.

  2. You can connect to AD using something like this:

    var username = "your username"; var password = "your password"; var domain = "your domain"; var ctx = new PrincipalContext(ContextType.Domain, domain, username, password);

  3. Then perform the operations using the PrincipalContext object. (There's a good example in the link that rickvdbosch gave.)

Related