0

I have C# windows service to create/update AD User properties. I am using PrincipalContext class for doing AD operation. Getting exception while creating Active Directory User.

Same code is working fine to update properties of existing users. Also service account has sufficient permission to create users in AD manually. Issue is only coming when we try to create user programatically.

using (var ADPrincipalContextSearch = new PrincipalContext(ContextType.Domain, "198.168.1.101", "OU=1. \=\=\= STAFF \=\=\=,DC=exch2016,DC=com"))
{
    var up = new UserPrincipal(ADPrincipalContextTarget);

    up.SamAccountName = userName;

    if (!String.IsNullOrEmpty(password))
    {
        up.SetPassword(password);
    }

    up.Enabled = true;
    if (passwordExpire)
    {
        up.ExpirePasswordNow();
    }

    up.Save();
}

Exception detail:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DirectoryServices.AccountManagement.PrincipalOperationException: Unknown error (0x80005000)

Vivek
  • 11
  • 4
  • try other implementation https://stackoverflow.com/questions/1722398/error-0x80005000-and-directoryservices and may be a permission problem – langme Sep 29 '21 at 14:06

0 Answers0