gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:57:29 25 4
gpt4 key购买 nike

我正在使用以下代码。该代码执行正常,但不会删除用户。

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 用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29084606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com