public void Core_CreateUserBadDistName() { // Get User That Does Not Exist String userName = $"testuser_{Utility.GenerateToken( 8 )}"; String userDistinguishedName = $"GW={userName},{workspaceName}"; Console.WriteLine($"Create User [{userDistinguishedName}] With Bad DistinguishedName"); UserPrincipal user = null; AdException ex = Assert.Throws <AdException>(() => user = DirectoryServices.CreateUserPrincipal(userDistinguishedName)); }
public static UserPrincipal CreateUser(string workspaceName) { String name = $"testuser_{Utility.GenerateToken( 8 )}"; String testUserName = $"CN={name},{workspaceName}"; Console.WriteLine($"Creating User : [{testUserName}]"); UserPrincipal testUser = DirectoryServices.CreateUserPrincipal(testUserName); DirectoryServices.SaveUser(testUser); Assert.That(testUser.Name, Is.EqualTo(name)); return(testUser); }
public UserPrincipal CreateUserPrincipal() { String name = this.Identity; String path = DirectoryServices.GetDomainDistinguishedName(); String domain = DirectoryServices.GetDomain( path ); UserPrincipal user = null; if ( DirectoryServices.IsDistinguishedName(this.Identity) ) user = DirectoryServices.CreateUserPrincipal( this.Identity, this.UserPrincipalName, this.SamAccountName ); if (this.Properties?.Count > 0) user.Save(); // User Must Exist Before Properties Can Be Updated. UpdateUserPrincipal( user ); return user; }