Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, October 11, 2013 4:32 PM | 1 vote
Hi,
I have power shell command that copies users from one group to another
Get-ADGroupMember "group1" | Get-ADUser | Foreach-Object {Add-ADGroupMember -Identity "group2" -Members $_}
how would I modify this command to move users and leave original group empty.
meaning that I don't want to leave users in the first group
Dalibor Bosic
All replies (5)
Friday, October 11, 2013 4:51 PM ✅Answered | 3 votes
There is not reason to pipe over to Get-ADUser, so you can try something like
Get-ADGroupMember "group1" | ForEach-Object {
Add-ADGroupMember -Identity "group2" -Members $_
Remove-ADGroupMember -Identity "group1" -Members $_
}
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Friday, October 11, 2013 4:52 PM ✅Answered
try this:
Get-ADGroupMember "group1" | Get-ADUser | Foreach-Object { Add-ADGroupMember -Identity "group2" -Members $_ Remove-ADGroupMember -Identity "group1" -Members $_ }
There is no "copy" function - all you are doing is getting a list of members from one group and adding them. Similarly there is no "move" function, so you simulate a move by following the add with the remove.
I suspect there is no copy-groupmember or move-groupmember function because group membership is not exclusive, as an account can be a member of any number of groups.
Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.
Wednesday, March 22, 2017 7:51 PM
Thanks clayman2, only one word of caution. The question asks how to copy members from one group to another. Your script moves from one group to the other. If you wanted to copy from one group to the other, do this:
Get-ADGroupMember "group1" | ForEach-Object {
Add-ADGroupMember -Identity "group2" -Members $_
}
Tuesday, November 21, 2017 11:46 AM
Hi guys,
How I can move first 100 entries from group 1 to group 2 ?
For example:
Group 1 - Have 1000 entries (Host Names of PC)
GrouP 2- Clear
I would like to move first 100 Hosts from Group 1 to Group 2.
It is possible?
Thanks :)
Thursday, January 10, 2019 11:01 AM
Thanks for this :)
Also you might want a -confirm:$false on add and remove, if there is many members and you are SURE that you want to to this.