

# By Alberto Igbinedion

# Add User to a DistributionGroup - PowerShell Script 
# Selecting Number of Users Options
#
#........Must Be Run As Administrator

Write-Host "Enter Group Name: " -ForegroundColor Green -NoNewline
$Identity = Read-Host

Write-Host "You Have 2 Options: 1 For Single User, 2 For Multiple User. (For Option 2 Make Sure You Have Prepared Your CSV in the Following Location)" -NoNewline
Write-Host "  C:\Scripts\input\Users.csv  " -ForegroundColor Yellow
Write-Host "Please Enter" -NoNewline
Write-Host " 1 " -ForegroundColor Yellow -NoNewline
Write-Host "For A Single User and" -NoNewline
Write-Host " 2 " -ForegroundColor Yellow -NoNewline
Write-Host "For Multiple Users: " -NoNewline
$Option = Read-Host

Write-Host "Enter" -NoNewline
Write-Host " Username: " -ForegroundColor Green -NoNewline
Write-Host "If Option " -NoNewline
Write-Host "1 " -ForegroundColor Yellow -NoNewline
Write-Host "OR Press " -NoNewline 
Write-Host "Enter " -ForegroundColor Green -NoNewline
Write-Host "For Option" -NoNewline
Write-Host " 2: " -ForegroundColor Yellow -NoNewline

$Member = Read-Host

$MultipleMember = Import-CSV "C:\Scripts\Input\Users.csv" | Select-Object -ExpandProperty name 


# Looping through The Selected Options And then Adding Members

While ($Option -ge 3)
{
Write-Host "This is not a valid Entry, please enter either 1 or 2"

$Option = Read-Host "How Many Users Do you want to Add ? 1=Single User, 2=Multiple Users"
}

If ($Option -eq 1)
{ Add-DistributionGroupMember -Identity $Identity -Member $Member


}elseif ($Option -eq 2) 
 { Add-DistributionGroupMember -Identity $Identity -Member $MultipleMember

}

#NewLine To Create Space

"`n"

# Check Who Are Members

Write-Host "Below Are Current List of Members for $Identity  " -ForegroundColor Green

Get-DistributionGroupMember -Identity $Identity | fl name


# Remove Memeber from DL 
# Remove-DistributionGroupMember -Identity "DLToRemoveMemeberFrom" -Member "MemberToRemove"