c# – 如何以编程方式删除Azure Active Directory用户?

我使用以下代码.
代码执行正常但不删除用户.

IUser deleteuser = new User();
deleteuser = users.Where(myuser => myuse

r.MailNickname.Equals("IshanArora")).FirstOrDefault();

if (deleteuser != null)
{
    deleteuser.DeleteAsync();
}
最佳答案
我在删除用户之前通过检索删除用户:

private async Task DeleteUser()
{
    ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();

    // Retrieve user from its displayname
    var user = await client.Users.Where(u => u.DisplayName == "user two").ExecuteSingleAsync();

    // Or Retrieve user from its principal name
    // var user = await client.Users.Where(u => u.UserPrincipalName== "user two").ExecuteSingleAsync();

    // Or Retrieve user from its id in the directory
    //var user = await client.Users.GetByObjectId("0b34c995-0970-4776-ae87-f66d384f9c45").ExecuteAsync();

    // Delete the user
    await user.DeleteAsync();
}

您应该注意到,在看到用户从Azure门户中删除之前可能需要几秒钟

转载注明原文:c# – 如何以编程方式删除Azure Active Directory用户? - 代码日志