Help! Group Addition/Removal Automation

I am fairly new to using Powershell, so hopefully this isn’t too sloppy to fix.

We are doing some group changes while migrating Citrix environments and we need to remove users from old AD security groups and add them to the new ones. There are 2 csv files, one has user SamAccountNames, the other has the list of old and new groups in corresponding columns.

My current setup looks like this:

$csv = Import-CSV -Path "Users.csv" #groupscv not used in current iteration. $groupcsv = Import-CSV -Path "Groups.csv" ForEach ($user in $csv) { $OldGrp = Get-ADUser $user.SamAccountName -Property memberof | Select -ExpandProperty memberof | Get-ADGroup | Select Name ForEach ($grp.Name in $OldGrp) { If ($grp.Name -eq "OLDGROUP") { Remove-ADGroupMember -Identity "OLDGROUP" -Members $user.SamAccountName -Confirm:$false Add-ADGroupMember -Identity "NEWGROUP" -Members $user.SamAccountName } } #Repeated for each old group/new group combo } 

Is there any way to have this automated and utilize the csv containing the old/new groups?

submitted by /u/Sounds_Like_Frown
[link] [comments]

Leave a Reply