当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] Get-MsolGroup - 获取 Microsoft 365 组报告

作者:精品下载站 日期:2024-12-14 06:26:09 浏览:13 分类:玩电脑

Get-MsolGroup - 获取 Microsoft 365 组报告


PowerShell 中的 Get-MsolGroup cmdlet 从 Microsoft Office 365 获取组。如果指定 ObjectId 参数,或在 Azure Active Directory 中的所有组中搜索,此命令将返回单个组。

下面给出了使用 PowerShell 从 Azure Active Directory 获取组列表的语法。

Get-MsolGroup
   [-UserObjectId <Guid>]
   -ObjectId <Guid>
   [-IsAgentRole]
   [-UserPrincipalName <String>]
   [-GroupType <GroupType>]
   [-HasErrorsOnly]
   [-HasLicenseErrorsOnly <Boolean>]
   [-SearchString <String>]
   [-MaxResults <Int32>]
   [-TenantId <Guid>]
   [<CommonParameters>]

在本文中,我们将讨论如何使用 PowerShell 中的 Get-MsolGroup cmdlet 获取 Azure Active Directory 中的组列表、按名称获取组以及使用用户主体名称获取组。

让我们通过示例来了解 Get-MsolGroup 命令。

如何获取 Microsoft 365 中的所有组

若要获取 Microsoft 365 中的所有组,请使用 Get-MsolGroup cmdlet。

Get-MsolGroup

此命令返回 Microsoft 365 中租户的整个组集。它最多返回默认的 250 个结果。

[玩转系统] Get-MsolGroup - 获取 Microsoft 365 组报告

如何在 Office 365 中获取按对象 ID 分组

要在 Office 365 中按名称获取组,请使用带有 -ObjectId 参数的 Get-MsolGroup cmdlet。 -ObjectId 参数指定要获取的组的唯一对象 ID。

Get-MsolGroup -ObjectId f876f049-21b1-450d-8961-7e63f49f232e

此命令返回具有指定对象 ID 的组对象。

上述命令的输出如下所示。

PS C:\> Get-MsolGroup -ObjectId f876f049-21b1-450d-8961-7e63f49f232e
ObjectId                               DisplayName                GroupType                  Description
--------                               -----------                ---------                  -----------
f876f049-21b1-450d-8961-7e63f49f232e   Security                   DistributionList           This is security group.


PS C:\>

如何使用 UserPrincipalName (UPN) 获取组

若要使用 Microsoft 365 中的用户主体名称获取组,请使用带有 -UserPrincipalName 参数的 Get-MsolGroup cmdlet。 -UserPrincipalName 参数指定用户的主体名称。

Get-MsolGroup -isAgentRole -UserPrincipalName "[email "

此命令返回该用户所属的安全组。 -UserPrincipalName 参数必须与-IsAgentRole 参数一起使用。 -IsAgentRole 参数指定 Get-MsolGroup 命令仅返回代理组。

如何获取以特定名称开头的组

若要获取 Microsoft 365 中以特定名称开头的组,请使用 PowerShell 中的 Get-MsolGroup cmdlet 获取所有组并将其通过管道传输到 Where-Object cmdlet。 Where-Object 命令检查组显示名称是否以指定单词开头的条件。

Get-MsolGroup | Where-Object {$_.DisplayName -like "*Finance*"}

此命令返回 Office 365 中显示名称中包含“Finance”的组。

PS C:\> Get-MsolGroup | Where-Object {$_.DisplayName -like "*Finance*"}

ObjectId                               DisplayName                  GroupType                    Description
--------                               -----------                  ---------                    -----------
008f363f-5b3a-4899-8004-a2d140426802   Finance                      DistributionList             This is the Finance Group


PS C:\>

如何在 Microsoft 365 中搜索组

要在 Microsoft 365 中搜索组,请在 PowerShell 中使用带有 -SearchString 参数的 Get-MsolGroup cmdlet。 -SearchString 参数指定一个字符串。

Get-MsolGroup -SearchString "Security"

Get-MsolGroup 命令返回显示名称以字符串“Security”开头的安全组。

PS C:\> Get-MsolGroup -SearchString "Security"

ObjectId                               DisplayName                  GroupType                    Description
--------                               -----------                  ---------                    -----------
f876f049-21b1-450d-8961-7e63f49f232e   Security                     DistributionList             This is security group.

如何使用组类型获取安全组

要使用组类型获取安全组,请使用带有 -GroupType 参数的 Get-MsolGroup cmdlet。 -GroupType 参数指定要获取的组的类型。有效值为 Security、MailEnabledSecurity 和 DistributionList。

 Get-MsolGroup -GroupType "Security" | Export-Csv -Path D:\PS\distributionlistGroups.csv -NoTypeInformation

此命令按组类型“Security”返回所有组,并将它们通过管道传输到Export-CSV cmdlet。 Export-CSV 命令导出安全组。它使用 -Path 参数来指定目标位置路径。

结论

希望上述有关如何在 PowerShell 中使用 Get-MsolGroup cmdlet 获取 Microsoft 365 组的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

相关链接

Set-Msol集团

新Msol集团

删除-MsolGroup

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯