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

[玩转系统] 如何将所有者添加到 Microsoft 365 组

作者:精品下载站 日期:2024-12-14 05:51:59 浏览:13 分类:玩电脑

如何将所有者添加到 Microsoft 365 组


Microsoft 365 组允许一组人员发送电子邮件并共享文件、日历和其他资源。所有者是 Microsoft 365 组的管理员,他们可以添加或删除成员以及更改组设置。在本文中,你将了解如何在 Microsoft Entra 管理中心和 PowerShell 中将所有者添加到 Microsoft 365 组。

先决条件

在开始将组所有者添加到 Microsoft 365 组之前,您需要创建 Microsoft 365 组。

Microsoft 365 组所有者

每个组织最多可以在 Microsoft 365 中创建 500,000 个组。下表显示了 Microsoft 365 组限制。

Microsoft 365 GroupMaximum valueNumber of owners per group100Number of members per groupMore than 1,000*Single user can create groups250Admin can create groups500,000 (default tenant limit)Number of groups a user can be a member of1,000File storage1 TB
10 GB per subscribed user
Additional storage purchased (unlimited)Mailbox size50 GB

*只有1,000人可以一起访问群组对话。

注意:用户在 Outlook 中访问大型组中的日历和对话时可能会注意到延迟。

使用 Microsoft 365 组,您无需手动向每个成员分配权限。您可以将完全访问邮箱权限分配给 Microsoft 365 组,这将自动向成员授予相同的权限。

建议 Microsoft 365 组至少有两名所有者。这样,如果一个所有者不可用,另一位所有者可以对 Microsoft 365 组进行更改。

Microsoft 365 组所有者可以:

  • 更改群组设置
  • 添加或删除群组成员
  • 删除群组
  • 从共享收件箱中删除对话
  • 重命名组
  • 更新描述或图片
  • 批准访客访问请求的邀请

将所有者添加到 Microsoft Entra ID 中的 Microsoft 365 组

要将所有者添加到 Microsoft Entra 管理中心的 Microsoft 365 组,请按照以下步骤操作:

  1. 登录 Microsoft Entra 管理中心
  2. 展开身份 > 组 > 所有组
  3. 从列表中单击Microsoft 365安全组类型

注意:可以在 Microsoft Entra ID 和 Microsoft Graph PowerShell 中将所有者添加到 Microsoft 365 组安全组

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 点击所有者

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 点击添加所有者

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 选择用户
  2. 点击选择

[玩转系统] 如何将所有者添加到 Microsoft 365 组

您已成功将组所有者添加到 Microsoft 365 组。

注意:一个 Microsoft 365 组最多可以有 100 个所有者。在 Microsoft Entra 管理中心中,您最多可以选择 100 个用户并将他们添加为所有者。

如何将所有者添加到 Microsoft 365 组

您可以使用 PowerShell 将单个或多个所有者添加到 Microsoft 365 组。 Microsoft 365 组最多可以有 100 个所有者。

注意:来宾用户不能是群组的所有者,即使他们是群组的成员。

连接到 Microsoft Graph PowerShell

在开始之前,您必须安装 Microsoft Graph PowerShell 模块。以管理员身份启动 Windows PowerShell 并运行以下命令。

Install-Module Microsoft.Graph -Force

重要提示:在运行 cmdlet 或脚本之前,请务必安装最新的 Microsoft Graph PowerShell 模块版本,以防止出现错误和不正确的结果。

使用以下范围运行 Connect-MgGraph cmdlet 以通过 Microsoft Graph 进行身份验证。

Connect-MgGraph -Scopes "User.ReadWrite.All", "Group.ReadWrite.All", "GroupMember.ReadWrite.All"

现在一切就绪,您可以通过 MS Graph PowerShell 使用命令。

将所有者添加到 Microsoft 365 组

在我们的示例中,我们将向 Microsoft 365 组(管理团队)添加单个所有者。我们将使用 New-MgGroupOwner PowerShell cmdlet。

请参阅将所有者添加到 Microsoft 365 组的 PowerShell 语法。

New-MgGroupOwner -GroupId "Group Object Id" -DirectoryObjectId "Owner Object ID"

运行以下 PowerShell 命令,使用 MS Graph PowerShell 将所有者添加到 Microsoft 365 组。

New-MgGroupOwner -GroupId "031f52ea-cb97-40fc-ab0f-73598f3fc66d" -DirectoryObjectId "41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5"

将多个所有者添加到 Microsoft 365 组

要将多个所有者添加到 Microsoft 365 组,您还可以指定 UserPrincipalName。

  1. 输入您要添加的所有者的 UPN
  2. 输入组对象 ID
  3. 运行以下 PowerShell 脚本
$upns = @(
    "[email protected]",
    "[email protected]",
    "[email protected]",
)
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"

$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

if ($Group) {

    foreach ($upn in $upns) {
        $User = Get-MgUser -Filter "userPrincipalName eq '$upn'"
        
        if ($User) {
            $UserId = $User.Id
            $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId
            
            if ($ExistingOwner.Id -eq $UserId) {
                Write-Host "User $($User.UserPrincipalName) already exists in the group." -ForegroundColor Yellow
            }
            else {
                New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $UserId
                Write-Host "User $($User.UserPrincipalName) added to the group." -ForegroundColor Green
            }
        }
        else {
            Write-Host "User $upn does not exist." -ForegroundColor Red
        }
    }
}
else {
    Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}

将批量所有者添加到 Microsoft 365 组

您可以使用 PowerShell 将所有所有者添加到单个 Microsoft 365 组。

注意:一个 Microsoft 365 组最多可以有 100 个所有者。当您将所有用户添加为所有者时,它只会按字母顺序添加前 100 个用户。

  1. 在第 编号 1 行中指定 Microsoft 365 组 ID
  2. 运行以下 PowerShell 脚本将用户作为所有者添加到单个 Microsoft 365 组
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"

$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

if ($Group) {
    $Users = Get-MgUser -All
    
    foreach ($User in $Users) {
        $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId
        
        if ($ExistingOwner.Id -eq $User.Id) {
            Write-Host "User $($User.UserPrincipalName) already exists as owner of the group." -ForegroundColor Yellow
        }
        else {
            New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $User.Id
            Write-Host "User $($User.UserPrincipalName) added as owner of the group." -ForegroundColor Green
        }
    }
}
else {
    Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}

如果所有者达到最大值 100,您将收到以下错误。

无法执行操作,因为“101”将超过前向链接“所有者”的最大配额计数“100”。

将特定部门的所有者添加到 Microsoft 365 组

在我们的示例中,我们希望将营销部门的所有用户添加到 Microsoft 365 组([email protected])。我们将使用 -Filter 参数和相等比较运算符 (-eq) 运算符,您可以在如何在 PowerShell 中使用比较运算符中阅读更多相关信息。

  1. 第 1 行中键入 Microsoft 365 组 ID
  2. 运行以下 PowerShell 脚本
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"

$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

if ($Group) {
    $Users = Get-MgUser -All -Filter "Department eq 'Marketing'"
    
    foreach ($User in $Users) {
        $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId
        
        if ($ExistingOwner.Id -eq $User.Id) {
            Write-Host "User $($User.UserPrincipalName) already exists as owner of the group." -ForegroundColor Yellow
        }
        else {
            New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $User.Id
            Write-Host "User $($User.UserPrincipalName) added as owner of the group." -ForegroundColor Green
        }
    }
}
else {
    Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}

它将把营销部门的每个人添加为 Microsoft 365 组的所有者 ([email protected])。

从 CSV 将多个所有者添加到 Microsoft 365 组

要将多个所有者添加到单个 Microsoft 365 组,我们需要使用 CSV 文件。

创建一个包含两列的 CSV 文件:

  1. 打开Microsoft Excel
  2. 输入 UPN 作为第一列的标题
  3. 指定UserPrincipalName
  4. 输入 OwnerID 作为第二列的标题
  5. 指定所有者对象 ID

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
  2. 将文件命名为 M365users.csv
  3. 保存类型为 CSV(逗号分隔 (*.csv)
  4. 点击保存

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 第 1 行中指定CSV 文件路径
  2. 第 2 行中键入 Microsoft 365 组 ID
  3. 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365users.csv"
$GroupId = "031f52ea-cb97-40fc-ab0f-73598f3fc66d"

$Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

if ($Group) {
    $CsvUsers = Import-Csv -Path $CsvFilePath

    foreach ($CsvUser in $CsvUsers) {
        $CsvUserID = $CsvUser.UserId
        $User = Get-MgUser -Filter "Id eq '$CsvUserID'" -ErrorAction SilentlyContinue
         
        if ($User) {
            $UserId = $User.Id
            $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId

            if ($ExistingOwner.Id -eq $UserId) {
                Write-Host "User $($User.UserPrincipalName) already exists as owner of the group." -ForegroundColor Yellow
            }
            else {
                New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $UserId
                Write-Host "User $($User.UserPrincipalName) added as owner of the group." -ForegroundColor Green
            }
        }
        else {
            Write-Host "User $CsvUserID does not exist." -ForegroundColor Red
        }
    }
}
else {
    Write-Host "Group $GroupId does not exist." -ForegroundColor Red
}

PowerShell 输出结果显示是否:

  • Microsoft 365 组不存在或拼写错误
  • 用户已作为 Microsoft 365 组的所有者存在
  • 用户被添加为 Microsoft 365 组的所有者
  • 用户不存在或拼写错误

从 CSV 将所有者添加到多个 Microsoft 365 组

您可以从 CSV 文件将所有者添加到多个 Microsoft 365 组。您需要创建一个由四列组成的 CSV 文件。前两列将包含 Microsoft 365 组的列表。第三列和第四列将包含您要添加为所有者的用户列表。

创建一个包含四列的 CSV 文件:

  1. 打开Microsoft Excel
  2. 输入 GroupName 作为第一列的标题
  3. 指定 Microsoft 365 组电子邮件
  4. 输入 GroupID 作为第二列的标题
  5. 指定 Microsoft 365组 ID
  6. 输入用户名作为第三列的标题
  7. 指定所有者UserPrincipalName
  8. 输入 OwnerID 作为第四列的标题
  9. 指定所有者对象 ID

请参阅下面的 CSV 文件示例。

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
  2. 将文件命名为 M365owners.csv
  3. 保存类型为 CSV(逗号分隔 (*.csv)
  4. 点击保存

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 第 1 行中指定CSV 文件路径
  2. 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365owners.csv"

$Csv = Import-Csv $CsvFilePath

foreach ($row in $Csv) {
    $GroupId = $Row.GroupID
    $OwnerId = $Row.OwnerID

    $Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

    if ($Group) {
        $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId
    
        if ($ExistingOwner.Id -eq $OwnerId) {
            Write-Host "User $OwnerId already exists in the group." -ForegroundColor Yellow
        }
        else {
            $User = Get-MgUser -Filter "Id eq '$OwnerId'" -ErrorAction SilentlyContinue
    
            if ($User) {
                New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $OwnerId
                Write-Host "User $OwnerId added to the group." -ForegroundColor Green 
            }
            else {
                Write-Host "User $OwnerId doesn't exist" -ForegroundColor Red
            }
        }
    }
    else {
        Write-Host "Group $GroupId does not exist." -ForegroundColor Red
    }
}

PowerShell 输出结果显示是否:

  • Microsoft 365 组不存在或拼写错误
  • 用户已经是 Microsoft 365 组的所有者
  • 用户已添加到 Microsoft 365 组
  • 用户不存在或拼写错误

使用 CSV 将单一所有者添加到所有 Microsoft 365 组

要将所有者添加到多个 Microsoft 365 组,您需要创建 CSV 文件。

在我们的示例中,我们希望将用户(Amanda Hansen)添加为多个 Microsoft 365 组的所有者。

创建一个包含两列的 CSV 文件:

  1. 打开Microsoft Excel
  2. 输入作为第一列的标题
  3. 指定 Microsoft 365 组主 SMTP 地址
  4. 输入 ObjectID 作为第二列的标题
  5. 指定 Microsoft 365 组对象 ID

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
  2. 将文件命名为M365groups.csv
  3. 保存类型为 CSV(逗号分隔 (*.csv)
  4. 点击保存

[玩转系统] 如何将所有者添加到 Microsoft 365 组

  1. 第 1 行中指定CSV 文件路径
  2. 第 2 行中输入所有者对象 ID
  3. 运行以下 PowerShell 脚本
$CsvFilePath = "C:\temp\M365groups.csv"
$UserId = "41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5"

# Check if the user exists
$User = Get-MgUser -UserId $UserId -ErrorAction SilentlyContinue

if ($User) {
    $CsvGroups = Import-Csv -Path $CsvFilePath

    foreach ($row in $CsvGroups) {
        $GroupId = $Row.ObjectID

        $Group = Get-MgGroup -GroupId $GroupId -ErrorAction SilentlyContinue

        if ($Group) {
            $ExistingOwner = Get-MgGroupOwner -GroupId $GroupId
            
            if ($ExistingOwner.Id -eq $UserId) {
                Write-Host "User $UserId already exists in the group." -ForegroundColor Yellow
            }
            else {
                New-MgGroupOwner -GroupId $GroupId -DirectoryObjectId $UserId
                Write-Host "User $UserId added to the group." -ForegroundColor Green
            }
        }
        else {
            Write-Host "Group $GroupId does not exist." -ForegroundColor Red
        }
    }
}
else {
    Write-Host "User $UserId does not exist." -ForegroundColor Red
}

就是这样!

阅读更多内容:如何使用 PowerShell 将所有者添加到分发组 »

结论

您了解了如何在 Microsoft Entra 管理中心和使用 PowerShell 将所有者添加到 Microsoft 365 组。您可以将单个、多个和所有用户作为所有者添加到 Microsoft 365 组。请记住,每个 Microsoft 365 组最多只能添加 100 个所有者。

您喜欢这篇文章吗?您可能还喜欢如何在 PowerShell 中使用逻辑运算符。不要忘记关注我们并分享这篇文章。

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

取消回复欢迎 发表评论:

关灯