##############################################################################
###################################################################################
$asciiNum=97..122
$letters=$asciiNum|ForEach-Object { [char]$_ }
$date = (Get-Date).AddDays(-15) #Last 15 Day
foreach($letter1 in $letters)
{
$filter=$letter1+"*"
$gname="TS.SAP_HKG_"+$letter1
$users= Get-ADUser -Filter {whenCreated -ge $date -and name -like $letter} -server hkg -Properties * | select name
If ($users -eq $null)
{
Write-Host -ForegroundColor Red "No user Exist in Last 15 days in Starting with $letter"
}
Else
{
foreach ($user1 in $users.name)
{
Add-ADGroupMember -Identity $gname -Members $user1
Write-Host -ForegroundColor Cyan "$user1 added to group $gname"
}
}
}
###################################################################################
$asciiNum=97..122
$letters=$asciiNum|ForEach-Object { [char]$_ }
$date = (Get-Date).AddDays(-15) #Last 15 Day
foreach($letter1 in $letters)
{
$filter=$letter1+"*"
$gname="TS.SAP_HKG_"+$letter1
$users= Get-ADUser -Filter {whenCreated -ge $date -and name -like $letter} -server hkg -Properties * | select name
If ($users -eq $null)
{
Write-Host -ForegroundColor Red "No user Exist in Last 15 days in Starting with $letter"
}
Else
{
foreach ($user1 in $users.name)
{
Add-ADGroupMember -Identity $gname -Members $user1
Write-Host -ForegroundColor Cyan "$user1 added to group $gname"
}
}
}