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

[玩转系统] 如何将通讯组列表转换为安全组

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

如何将通讯组列表转换为安全组


在 Microsoft 365 中,您无法将通讯组列表转换为启用邮件的安全组。使用 PowerShell 脚本,可以将相同的成员从通讯组列表复制到安全组。在本文中,您将了解如何将通讯组列表转换为启用邮件的安全组,反之亦然。

分发与安全组

在我们将通讯组列表转换为 Microsoft 365 中启用邮件的安全组之前,了解它们的差异非常重要。

  • 通讯组用于向一组人发送电子邮件通知。
  • 启用邮件的安全组用于向所有组成员发送电子邮件并授予他们对 SharePoint 等资源的访问权限。

[玩转系统] 如何将通讯组列表转换为安全组

我们可以使用通讯组列表和启用邮件的安全组向每个成员发送电子邮件通知。

这些组之间的主要区别在于我们只能使用安全组来分配权限。这意味着我们不能使用通讯组列表组来分配权限。通讯组未启用安全性,这意味着它们不能列在自主访问控制列表 (DACL) 中。

下表显示通讯组列表和启用邮件的安全组之间的差异。

Assign permissions

是的

Send an email to the group

是的

如果您为安全组分配权限,则所有组成员都会自动继承分配给该组的权限。

  • 当您将新用户添加到安全组时,它将自动继承分配给安全组的权限。
  • 从安全组中删除用户将自动删除分配给该组成员的权限。

连接到 Exchange Online PowerShell

为了能够运行 PowerShell 命令,您必须连接到 Exchange Online PowerShell。以管理员身份打开 Windows PowerShell,运行以下 cmdlet,然后使用管理员凭据登录。

Connect-ExchangeOnline

将成员从通讯组列表复制到安全组

Exchange Online 中没有将现有通讯组列表转换为启用邮件的安全组的选项。因此,我们需要使用PowerShell将通讯组列表中的所有成员复制到现有的安全组中。

[玩转系统] 如何将通讯组列表转换为安全组

我们将向您展示将通讯组列表复制到安全组中的步骤:

  1. 创建新的启用邮件的安全组

首先,您需要拥有一个现有的安全组或创建一个新的安全组。在我们的示例中,我们将创建一个新的启用邮件的安全组([email protected])

运行以下 Powershell 示例来创建新的安全组。

New-DistributionGroup -Name "Finance UK" -PrimarySmtpAddress "[email protected]" -ManagedBy "[email protected]" -Type Security
  1. 将现有通讯组列表中的所有成员复制到新安全组

下一步是将通讯组列表的成员转换为新的启用邮件的安全组。

请参阅下面的 PowerShell 示例语法。

$Members = Get-DistributionGroupMember -ResultSize Unlimited -Id "Distribution Group"
foreach ($Member in $Members) {
    Add-DistributionGroupMember -Identity "Security Group" -Member $Member.name
}

我们希望将(英国销售)通讯组列表的相同成员复制到启用邮件的安全组(英国财务)

  • 第 1 行中指定通讯组列表主 SMTP 地址
  • 第 3 行中指定启用邮件的安全组主 SMTP 地址
  • 运行以下 PowerShell 脚本

注意:要将成员从启用邮件的安全组复制到通讯组列表,您需要在 PowerShell 脚本中反转组的顺序。

$Members = Get-DistributionGroupMember -ResultSize Unlimited -Id "[email protected]"
foreach ($Member in $Members) {
    Add-DistributionGroupMember -Identity "[email protected]" -Member $Member.name -BypassSecurityGroupManagerCheck
}

您已将所有通讯组列表成员转移到启用邮件的安全组。

  1. 最后一步是删除通讯组

运行以下 PowerShell 命令来删除通讯组。

Remove-DistributionGroup "[email protected]" -BypassSecurityGroupManagerCheck -Confirm:$false

如果您想要使用 PowerShell 自动将通讯组列表转换为启用邮件的安全组,请选择下一个选项。

将通讯组列表所有者和成员转换为安全组

要将所有所有者和成员从通讯组列表复制到新创建的安全组,我们需要使用不同的方法。

我们创建了一个 PowerShell 脚本,它将:

  • 创建新的启用邮件的安全组
  • 将所有者和成员从现有通讯组列表复制到新创建的安全组
  • 删除原来的通讯组列表

注意:您无法使用相同的主 SMTP 地址创建另一个组。

以下脚本将自动创建一个与通讯组同名的新安全组。但我们需要在新创建的安全组的主SMTP地址末尾临时添加-New。最后,该脚本将从启用邮件的安全组的主 SMTP 地址中删除原始通讯组和-New

  1. 在行号 1 中指定管理员 UPN
  2. 在第 2 行中指定通讯组列表组主 SMTP 地址
  3. 运行以下 PowerShell 脚本

注意:要将启用邮件的安全组转换为通讯组列表,您需要删除以下 PowerShell 脚本中第 25 行的-Type Security

$Admin = "[email protected]"
$DistributionGroup = "[email protected]"

# Connect to Exchange Online PowerShell
Connect-ExchangeOnline

# Get distribition group
$DG = Get-DistributionGroup -ResultSize Unlimited -Identity $DistributionGroup -ErrorAction SilentlyContinue

# Check if group exist
if ($DG -eq $null) {
    Write-Host "The distribution group '$DistributionGroup' does not exist." -ForegroundColor Red
}
else {
    # Get all the members of the distribution group
    $Members = Get-DistributionGroupMember -ResultSize Unlimited -Identity $DistributionGroup
    $Owners = $DG.ManagedBy

    # Split the distribution group address
    $GroupName = $DG.DisplayName
    $SplittedAddress = $DG.PrimarySmtpAddress -split "@"
    $PrimarySmtpAddressNew = "$($SplittedAddress[0])-New@$($SplittedAddress[1])"

    # Create a new security group with a name based on the distribution group
    $null = New-DistributionGroup -Name $GroupName -PrimarySmtpAddress $PrimarySmtpAddressNew -Type Security
    Write-Host "Created NEW security group $GroupName ($PrimarySmtpAddressNew)." -ForegroundColor Green

    # Loop through each owner of the original group
    Write-Host "Adding owners to security group $GroupName ($PrimarySmtpAddressNew)." -ForegroundColor Green
    foreach ($Owner in $Owners) {
        # Add the owner to the new security group
        Set-DistributionGroup -Identity "$PrimarySmtpAddressNew" -ManagedBy @{Add = $Owners } -BypassSecurityGroupManagerCheck -ErrorAction Stop
    }

    # Loop through each member of the original group
    Write-Host "Adding members to security group $GroupName ($PrimarySmtpAddressNew)." -ForegroundColor Green
    foreach ($Member in $Members) {
        # Add the member to the new security group
        Add-DistributionGroupMember -Identity "$PrimarySmtpAddressNew" -Member $Member.Identity -BypassSecurityGroupManagerCheck -ErrorAction SilentlyContinue
    }

    # Remove admin from new security group
    Set-DistributionGroup -Identity "$PrimarySmtpAddressNew" -ManagedBy @{Remove = $Admin } -BypassSecurityGroupManagerCheck -ErrorAction Stop
    Write-Host "Removed admin $($Admin) from security group $GroupName ($PrimarySmtpAddressNew)." -ForegroundColor Green

    # Remove the original distribution group
    Remove-DistributionGroup -Identity "$DistributionGroup" -BypassSecurityGroupManagerCheck -Confirm:$false
    Write-Host "Removed Distribution Group $($DistributionGroup)." -ForegroundColor Green

    # Remove the -New from the security group
    Set-Distributiongroup -Identity $PrimarySmtpAddressNew -PrimarySmtpAddress $DistributionGroup
    Write-Host "Updated security group primary SMTP address to $($DistributionGroup)." -ForegroundColor Green
}

PowerShell 输出结果显示通讯组列表的成员和所有者已转移到新安全组。它删除了原始通讯组列表,新安全组的主 SMTP 地址现在与原始通讯组列表相同。

Created NEW security group Sales UK ([email protected]).
Adding owners to security group Sales UK ([email protected]).
Adding members to security group Sales UK ([email protected]).
Removed admin [email protected] from security group Sales UK ([email protected]).
Removed Distribution Group [email protected].
Updated security group primary SMTP address to [email protected].

就是这样!

阅读更多:如何分配完全访问邮箱权限 »

结论

您学习了如何将通讯组转换为安全组。首先,PowerShell 脚本将创建一个新的启用邮件的安全组。接下来,它将把通讯组列表的所有者和成员转换为新创建的启用邮件的安全组。截至最后,它将删除通讯组列表。

您喜欢这篇文章吗?您可能还喜欢使用 PowerShell 管理用户邮箱。不要忘记关注我们并分享这篇文章。

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

取消回复欢迎 发表评论:

关灯