2017-02-22 4 views
0

Microsoft Azure로 마이그레이션해야하며 Azure가 Exchange의 AD 그룹을 처리 할 수 ​​없기 때문에 spezifc 그룹의 구성원을 가져 와서 교환해야합니다. 그래서 나는 이것을 powershell로 얻을 수 있다고 생각했습니다.Exchange의 AD 그룹을 해당 AD 그룹의 사용자로 바꾸십시오.

프린 :

내가 사서함 이름이 같은 CSV에서 추출 할 수있는 그룹이 있습니다

의 Mailbox1 GroupForMailbox1

Mailbox2 GroupForMailbox2

Mailbox2 GroupForMailbox2

그룹에서 모든 사용자를 추출하는 방법을 알고 있습니다 :

Get-ADGroupMember -identity "GroupForMailbox1" -Recursive 

하지만 문제는이 그룹에 그룹을 만들어서 사용자를 끌어 내고 싶지 않다는 것입니다. "ExcludedGroup"이라고합니다. 그룹 "ExcludedGroup"을 제외한 모든 AD 그룹 회원을 어떻게 얻을 수 있습니까?

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

foreach ($Users){ 

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

하지만 난 때문에 지식의 부족으로 하나의 스크립트에이의 모든 적합하지 못할 :

은 그 때 나는 특정 사서함에 그 AD 회원을 넣어해야합니다.

그리고 나는 하늘에서 정말로 문제가되는 인터넷에서도 뭔가를 찾을 수 없습니다.

누군가 나를 도와 줄 수 있다고 생각했습니다.

답변

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 
    } 
} 
+0

완벽하게 작동합니다! 이 스크립트를 공유해 주셔서 감사합니다 :) –