# By Alberto Igbinedion

# Add User to a Group - PowerShell Script 
# Selecting Number of Users Options
#
#....... This Script Needs Active Directory module installed
#........Must Be Run As Administrator

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

Import-module ActiveDirectory 
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\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-ADGroupMember -Identity $Identity -Members $Member


}elseif ($Option -eq 2) 
 { Add-ADGroupMember -Identity $Identity -Members $MultipleMember

}

#NewLine To Create Space

"`n"

# Check Who Are Members

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

Get-ADGroupMember -Identity $Identity | fl name

# Remove Member From Security Group
# remove-adgroupmember -Identity "GroupName" -Member "UserToRemove"

