如何删除孤立组在Azure AD PowerShell
使用PowerShell,您可以删除Azure AD中的孤立组。我将解释如何从Azure AD中删除已同步到您的租户中但在删除Azure AD Connect后留下的组。
在你移除Azure AD连接,您会发现Azure AD有许多孤立的组,这些组在本地Active Directory中不再存在。这些组没有任何用途,因此您可以安全地删除它们。
下面是Azure AD中存在的孤立组的示例。您可以通过登录找到所有孤立的组Azure门户>组.

您不能对这些孤立的组进行任何更改。如果您选择任何孤立组,则没有删除选项。不能从Azure Portal GUI中删除这些孤立组,但可以使用Azure AD PowerShell删除它们。

尝试手动管理或删除通过从Azure Active directory (Azure AD)的目录同步创建的对象。按微软,在以下情况下,您必须手动删除孤立对象。
- 案例1—本地AD DS不再可用。因此,您不能从内部环境中管理或删除对象。
- 案例2-您从本地AD DS中删除了一个对象。但是,该对象没有从您的云服务组织中删除。欢迎您~这是意想不到的行为。
当您试图从Microsoft 365删除用户帐户时,它会失败并报错。这是解决方案无法删除此用户,因为帐户已同步.
如何在Azure AD中删除孤立组
让我们看看在Azure AD中删除孤立组的步骤。
要通过PowerShell在Azure中管理用户和组,您需要安装Azure Active Directory PowerShell模块。
打开提升的Windows PowerShell命令提示符(以管理员身份运行Windows PowerShell)。执行以下命令安装Microsoft Azure Active Directory Module for Windows PowerShell。
安装模块-Name MSOnline
安装Azure AD PowerShell模块之后,运行该命令Connect-MsolService
.
此命令连接到Azure的广告.使用分配了“全局管理员”角色的帐户登录到Azure AD租户。您必须是租户管理员(即全局管理员)才能使用PowerShell成功地与Microsoft 365租户建立连接。

使用PowerShell成功登录到Azure AD后,让我们找到Azure AD中出现的组。
运行以下PowerShell命令查找Azure AD中的所有组。
Get-MsolGroup
输出现在应该显示Azure AD中出现的所有组以及它们的ObjectID、DisplayName、GroupType和Description。

现在可以使用以下PowerShell命令删除Azure AD中的孤立组。
Get-MsolGroup -SearchString "DisplayName" |删除msolgroup
其中,将DisplayName替换为孤立的组名。系统将要求您确认是否继续执行删除操作。选择Y删除孤立组。
Remove-MSolGroup命令从Azure AD中删除组。

如果要删除Azure AD中的所有孤立组,可以运行以下PowerShell命令。
Get-MsolGroup | Remove-MsolGroup -F
删除孤立组后,执行该命令Get-MsolGroup
,现在它不应该返回任何组。这也意味着您已经成功地从Azure AD中删除了孤立组。

现在让我们确认是否删除了孤立的组Azure AD租户.在Azure门户中,转到组,现在您可以看到所有孤立的组都已从Azure AD中删除。

使用PowerShell删除Azure AD组
当我从Azure活动目录中删除租户时,我发现Azure AD中的一些组没有被删除。这些组是从本地AD服务器同步的。下面是另一种使用PowerShell删除Azure AD组的方法。的Remove-AzureADGroupcmdlet从Azure活动目录(AD)中移除一个组。
下面的截图显示有三个组需要删除。当您选择组时,删除选项是灰色的,因此您必须使用PowerShell删除它们。

启动Azure Cloud She欢迎您~ll并等待它的加载。现在运行connect-azuread命令。命令执行成功后,可以使用以下命令删除组。
Remove-AzureADGroup -ObjectId '指定组的对象'
运行上述命令后,等待几秒钟,该组将在后台删除。

谢谢你,这正是我想要的
Remove-MsolGroup:不能删除此组。
在行:1字符:58
| Remove-MsolGroup -SearchString " Nidd Transport EOL users
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo: OperationStopped: (:) [Remove-MsolGroup], MicrosoftOnlineException
+ FullyQualifiedErrorId: Microsoft.Online.Administration.Automation.GroupDeletionNotAllowedException,Microsoft.On
line.Administration.Automation.RemoveGroup
同样的问题。
在我的例子中,发生上述错误是因为我将该组的许可证分配给该组成员。在删除该组的所有许可证(Azure Active Directory)后,我能够通过Remove-MsolGroup命令删除该组而不会出现错误。
有可能确定哪些群体是孤儿吗?
我在ad安全组中运行“disabled - disstrubtiongroup”后也有同样的问题。