-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDLPlusAddMembers.ps1
More file actions
34 lines (32 loc) · 1.63 KB
/
CreateDLPlusAddMembers.ps1
File metadata and controls
34 lines (32 loc) · 1.63 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
Connect-ExchangeOnline
$DLName = Read-Host -Prompt "Enter the name of the DL"
$NameAlias = Read-Host -Prompt "Enter the first and last name of the alias ex : Test.test"
$DLDisplayName = Read-Host -Prompt "Enter the display nameof the DL"
$EmailDL = Read-Host -Prompt "Enter the group mail"
New-DistributionGroup -Name "$DLName" -Alias "$NameAlias" -PrimarySmtpAddress "$EmailDL" -DisplayName "$DLDisplayName"
if ($?)
{Write-Host DL Succesfully Created -ForegroundColor Green}
else
{Write-Host -ErrorAction Stop -ForegroundColor Red | Disconnect-ExchangeOnline}
# Ask for moderation
$Ask1 = Read-Host -Prompt "Do you want to add moderation to this DL ? Y/N"
if ($Ask1 -eq "Y"){
$AdminUser = Read-Host -Prompt "Enter the Group User Manager"
Set-DistributionGroup -Identity "$NameAlias" -ManagedBy "$AdminUser" -ModerationEnabled:$True -ModeratedBy "$AdminUser"
if ($?)
{Write-Host DL Succesfully Updated -ForegroundColor Green}
else
{Write-Host -ErrorAction Stop -ForegroundColor Red | Disconnect-ExchangeOnline}}
if ($Ask1 -eq "N") {
$Ask = Read-Host -Prompt "Do you want to add members to this DL ? Y/N"
while($Ask -eq "Y"){
$Members = Read-Host -Prompt "Enter the members name for this DL or CTRL + C to break"
Update-DistributionGroupMember -Identity "$NameAlias" -Members $Members -Confirm:$True
if ($?)
{Write-Host Members Succesfully Add -ForegroundColor Green}
else
{Write-Host -ErrorAction Stop -ForegroundColor Red}
Get-DistributionGroupMember -Identity "$NameAlias"}}
if ($Ask -eq "N"){
Write-Host "No need more user, Disconnect" -ForegroundColor Green | Disconnect-ExchangeOnline}
Disconnect-ExchangeOnline