Here's another version of the code submitted by @Thameur-BOURBITA :
$Group = 'Group1'
Import-Csv -path c:\temp\input.csv |
ForEach-Object{
$UPN = $_.upn # needed for "Catch" block
$samaccountname = Get-ADUser -Filter "UserPrincipalName -eq '$UPN'" -Erroraction SilentlyContinue |
Select-Object –ExpandProperty Samaccountname
if ($samaccount){
Try{
Remove-ADGroupMember -Identity $Group1 -Members $SamAccountName -confirm:$false -Erroraction stop
Add-content -path c:\temp\_.log -value "$UPN has been removed successfully from $Group"
}
Catch{
Add-content -path c:\temp\_.log -value "$UPN was not removed from group '$Group' -- ERROR $_"
}
}
else{
Add-content -path c:\temp\_.log -value "$UPN was not found"
}
}
Add-content -path c:\temp\_.log -value "---END---"
I think you need to reexamine those filter strings!
Check the Get-ADUser help and read the "Note" in the description of the -Filter parameter.
I will test it. thank you for your feedback.