0
newUser.DisplayName = objUser.DisplayName;
            newUser.UserPrincipalName = objUser.UserPrincipalName;
            newUser.AccountEnabled = true;
            newUser.MailNickname = "SampleAppDemoUser";
            newUser.CompanyName = objUser.CompanyName;
            newUser.PasswordProfile = new PasswordProfile
            {
                Password = objUser.PasswordProfile.Password,
                ForceChangePasswordNextLogin = objUser.PasswordProfile.ForceChangePasswordNextLogin
            };

            newUser.Mobile = objUser.Mobile;
            newUser.Department = objUser.Department;
            newUser.JobTitle = objUser.JobTitle;
            newUser.City = objUser.City;
            newUser.UsageLocation = objUser.UsageLocation;


ActiveDirectoryClient clientUserCreate = AuthenticationHelper.GetActiveDirectoryClientAsApplication();
clientUserCreate.Users.AddUserAsync(newUser).Wait(10000);
var userid = newUser.ObjectId;

I am trying to create AAD user using above code. It is not throwing any error. Code runs smoothly. But it is not creating user in AD. When I am trying to get objectid of newly created user it gives null value.

If you have any idea then please suggest me. Is this issue related to Azure Configuration or permission or related to code ?

4
  • 2
    How have you defined your newUser? If it's not defined, nothing will be added.
    – moe
    Jun 1, 2017 at 10:01
  • Please check I have edited my answer now with newuser object setting Jun 1, 2017 at 10:11
  • I assume you have also registered the newUser variable too. Have you done this as IUser newUser = new User();?
    – moe
    Jun 1, 2017 at 10:45
  • Yes I have done that Jun 1, 2017 at 11:23

1 Answer 1

0

Instead of creating object assigning property then after was the cause of it.

I had replaced code from :

Microsoft.Azure.ActiveDirectory.GraphClient.User objUser = new Microsoft.Azure.ActiveDirectory.GraphClient.User();

objUser.DisplayName = "Test";

objUser.AccountEnabled  = true;
...

to

Microsoft.Azure.ActiveDirectory.GraphClient.User objUser = new Microsoft.Azure.ActiveDirectory.GraphClient.User

{

DisplayName = "Test";

AccountEnabled  = true;

...

};

I have not figure out what is the difference between those two methods but it solves my issue. If you can figure out that difference then please post it.

1
  • Mark this as answer if it helps you. Jun 23, 2017 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.