working on trying to add a user to a group from a csv.
checking if that user is already a member of the group. if so do nothing…
if not… then add user to group. provide some level of feedback
I have this already.
it seems to work close to ok… I get a return where as some users don’t appear to be in AD, but I suspect its due to hyphenated names and apostrophes. if I am correct in this… how can I correct / compensate for the bad characters?
or…
is there a better way to do this?
[pre]
foreach ($line in $userlist) {
$student = $line.stuid
$STUADName = “CN=”+$line.firstname+" “+$line.lastname+”,"+ $ou
$totalstudentsonlist++
# $error.clear()
try {
Get-ADUser -Filter { memberOf -RecursiveMatch $group } -SearchBase $STUADName -SearchScope Base -ErrorAction stop
“$student user is a member of the group”
$memberofgroup++
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
"$student ..may not exist in AD or could be naming convention error"
$StuNotInADError=$true
$studentnotinAD++
if (!$StuNotInADError){
"$student is in AD"
$needtoaddmembertogroup++
}
}
}
[pre/]