gpt4 book ai didi

powershell - 从 AzureAD/Office 365 清除已删除的外部用户失败并出现 UserNotFoundException

转载 作者:行者123 更新时间:2023-12-03 00:41:20 26 4
gpt4 key购买 nike

我正在尝试从 Office 365/AzureAD 中清除已删除的用户。这样做的方法似乎是 Remove-MsolUser -RemoveFromRecycleBin旗帜。

我可以检索用户

Get-MsolUser -All -ReturnDeletedUsers | ? {$_.userPrincipalName -eq $USERNAME}

当我尝试删除它时
Remove-MsolUser -UserPrincipalName $USERNAME -RemoveFromRecycleBin

我得到
Remove-MsolUser : User Not Found in the Microsoft Online directory Deleted Users container.  User:
xxxxxx#EXT#@yyyyyyyyy.
In Zeile:1 Zeichen:1
+ Remove-MsolUser -UserPrincipalName $USERNAME -RemoveFromRecycleBin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Remove-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Admini
stration.Automation.RemoveUser

https://support.microsoft.com/en-us/help/3019157/remove-msoluser-user-not-found-error-when-you-try-to-remove-a-user-fro状态

This problem occurs if the user who is performing the action is not a global admin.



但是我使用 全局管理员。

最佳答案

在这种情况下,最好通过管道输出 Get-MsolUser -All -ReturnDeletedUsers | ? {$_.userPrincipalName -eq $USERNAME}直接到Remove-MsolUser .
这样,ObjectID使用属性代替 UserPrincipalName,后者在添加到回收站后似乎已更改 ( #EXT# )。
ObjectID (a guid) 但是不会改变并且唯一标识用户对象。

尝试:

Get-MsolUser -All -ReturnDeletedUsers | ? {$_.userPrincipalName -eq $USERNAME} |
Remove-MsolUser -RemoveFromRecycleBin

或者:
$exUser = Get-MsolUser -All -ReturnDeletedUsers | ? {$_.userPrincipalName -eq $USERNAME}
Remove-MsolUser -ObjectId $exUser.ObjectID -RemoveFromRecycleBin

关于powershell - 从 AzureAD/Office 365 清除已删除的外部用户失败并出现 UserNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61210567/

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