[英]Replace AD Group in Exchange with Users in that AD Group
我們必須遷移到Microsoft Azure,並且由於Azure無法處理Exchange中的AD組,因此我必須獲取spezifc組的成員,然后將其添加以進行交換。 因此,我認為我可以通過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
}
但是由於缺乏知識,我無法將所有這些都放在一個腳本中。
我無法在互聯網上找到任何東西,盡管這是天青的真正問題。
我以為有人可以幫助我。
像這樣嗎
#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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.