-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistribution group migration tool.ps1
More file actions
51 lines (46 loc) · 2.05 KB
/
Distribution group migration tool.ps1
File metadata and controls
51 lines (46 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$Hidden = Get-DistributionGroup -identity "TEST"
$HiddenGroupVars = @()
foreach ($Group in $Hidden) {
$members = $NULL
$GroupName = $Group.Name
$members = Get-DistributionGroupMember -Identity $GroupName
New-Variable -Name $Group.Name -Value $members
$HiddenGroupVars += $Group.Name
}
Get-PSSession | Remove-pssession
Connect-ExchangeOnline
foreach($Variable in $HiddenGroupVars){
$Name = Get-Variable -Name $Variable
$Group = ( $Hidden | Where-Object -Property Name -eq $Name.Name )
$GroupMembers = @((Get-Variable -Name $Group).Value.PrimarySmtpAddress.Replace(" ", ", "))
$X500 = "X500:" + $Group.legacyExchangeDN
$New = @{
MemberJoinRestriction = $Group.MemberJoinRestriction
MemberDepartRestriction = $Group.MemberDepartRestriction
Alias = $Group.Alias
DisplayName = $Group.DisplayName
PrimarySmtpAddress = $Group.PrimarySmtpAddress
SendModerationNotifications = $Group.SendModerationNotifications
Name = $Group.Name
}
if(!($Group.RequireSenderAuthenticationEnabled -eq $Null)){
$New += @{RequireSenderAuthenticationEnabled = $true}
}
Out-Host -inputObject ("Creating: " + $Group.PrimarySmtpAddress)
New-DistributionGroup @New -whatif
if($Group.ModerationEnabled -eq $true){
Out-Host -inputObject "Moderation will need to be enabled manualy! `n"
pause
}
Out-Host -inputObject "Done! `nAdding X500 address."
Set-DistributionGroup -identity $Group.Name -EmailAddresses @{Add = $X500} -whatif
Out-Host -inputObject "Done!"
if($Group.HiddenFromAddressListsEnabled -eq $true){
Out-Host -inputObject "Hiding from address list."
Set-DistributionGroup -identity $Group.Name -HiddenFromAddressListsEnabled $true -whatif
Out-Host -inputObject "Done!"
}
Out-Host -inputObject "Adding members."
$GroupMembers | Foreach{ Add-DistributionGroupMember -Identity $Group.Name -Member $_ -whatif }
Out-Host -inputObject ($Group.Name + ": Configured!")
}