Compare-Object
Edited the code as Rob Simmers import CSV example was better, this is just a different way to do the foreach loop at the bottom of his code.
$ad = Get-ADGroupMember $classNameFiltered $result = Compare-Object $csv.loginName $ad.samaccountname $remove = $result | ?{$_.SideIndicator -eq "=>"} $add = $result | ?{$_.SideIndicator -eq "<="} foreach($loginName in $remove.inputobject){Remove-ADGroupMember -Identity $classNameFiltered -Members $loginName -whatif} foreach($loginName in $add.inputobject){Add-ADGroupMember -Identity $classNameFiltered -Members $loginName -whatif}
Editor code formatting is changing the SideIndicator operators, thus double check those and change as needed.