【问题标题】:Replace AD Group in Exchange with Users in that AD Group将 Exchange 中的 AD 组替换为该 AD 组中的用户
【发布时间】:2017-07-12 17:44:38
【问题描述】:

我们必须迁移到 Microsoft Azure,由于 Azure 无法处理 Exchange 中的 AD 组,我必须获取 spezifc 组的成员,然后将它们添加到 Exchange。所以我想我可以用 powershell 来实现。

原则:

我有邮箱名称和必须在 csv 中提取的组,如下所示:

Mailbox1 GroupForMailbox1

Mailbox2 GroupForMailbox2

Mailbox2 GroupForMailbox2

我知道如何从组中提取所有用户:

Get-ADGroupMember -identity "GroupForMailbox1" -Recursive

但问题是,这个组中有一个组,我不想让用户离开它。让我称之为“ExcludedGroup”。如何获取除“ExcludedGroup”组之外的所有 AD 组成员?

那我得把那些AD会员放到具体的邮箱里:

$Users= "Users that I've got out of the upper command"

foreach ($Users){

Add-MailboxPermission -Identity "Mailbox1" -User $Users Accessright Fullaccess -InheritanceType all
}

但由于缺乏知识,我无法将所有这些都放在一个脚本中。

我在互联网上找不到任何东西,虽然这是 azure 的一个真正问题。

我认为有人可以帮助我。

【问题讨论】:

    标签: powershell active-directory exchange-server


    【解决方案1】:

    这样的?

    #Sample data
    $csv = @"
    Mailbox,GroupName
    Mailbox1,GroupForMailbox1
    Mailbox2,GroupForMailbox2
    Mailbox2,GroupForMailbox2
    "@ | ConvertFrom-Csv
    
    #Uncomment to import file
    #$csv = Import-CSV -Path MyInputFile.csv
    
    $ExcludedUsers = Get-ADGroupMember -Identity "ExcludedGroup" -Recursive | Select-Object -ExpandProperty SamAccountName
    
    $csv | ForEach-Object {
        $mailbox = $_.Mailbox
    
        #Get members for group
        Get-ADGroupMember -Identity $_.GroupName -Recursive |
        #Remove unwanted users and keep only user objects (remove groups, computers etc.)
        Where-Object { ($ExcludedUsers -notcontains $_.SamAccountName) -and ($_.objectclass -eq 'user') } |
        ForEach-Object {
            #Grant each group member permission
            Add-MailboxPermission -Identity $mailbox -User $_.SamAccountName -AccessRights FullAccess -InheritanceType All
        }
    }
    

    【讨论】:

    • 完美运行!感谢分享这个脚本 :)
    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多