Istanbul/Turkey

Add/Remove Existing Group Users to Another Group

You can run the following command to add TestGroup's users as a member to TesGroup2

 

Get-ADGroupMember -Identity TestGroup | foreach {Add-ADGroupMember -Identity TestGroup2 -Members $_.SamAccountname}

 

 

This command does the opposite, it removes a groups users from other group. It removes TestGroup users from TestGroup2 users.

Get-ADGroupMember -Identity TestGroup | foreach {remove-ADGroupMember -Identity TestGroup2  -Members $_.Samaccountname -confirm:$false}

 

The command below imports the csv or txt file and removes the users from MiniTabUsers 

import-csv "C:\engr252.txt" | % { Remove-ADGroupMember -Identity MinitTabUsers -Members $_.user -Confirm:$false }

 

Txt File is in the following format

User

user1

user2

user3

  • Hits: 2303