question

JonHatfield-9686 avatar image
0 Votes"
JonHatfield-9686 asked JonHatfield-9686 answered

If User is Member of Group A, Remove Group A, then add to Group B

Title says it all. I'm trying to create a PowerShell script that will do the following:

Search for all members of Group A

Remove from Group A

Add to Group B

Any tips are appreciated!

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered

The script should look like this (not tested!)

 Import-Module ActiveDirectory
 Get-ADGroupMember -Identity "GroupA" |
         ForEach-Object {Add-AzADGroupMember -Identity "GroupB" -Members $_
                         Remove-ADGroupMember "GroupA" $_ -Confirm:$false
                        }

https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adgroupmember?view=win10-ps
https://docs.microsoft.com/en-us/powershell/module/addsadministration/add-adgroupmember?view=win10-ps
https://docs.microsoft.com/en-us/powershell/module/addsadministration/remove-adgroupmember?view=win10-ps


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JonHatfield-9686 avatar image
0 Votes"
JonHatfield-9686 answered

That worked perfectly. Thank you!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.