Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Group Membership Add-Remove based on .csv

$
0
0

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 "<=&quot;}
 
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.


Viewing all articles
Browse latest Browse all 13067

Trending Articles