Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove multiple users from an AD group with powershell

Posted on 2016-09-26
4
Medium Priority
?
47 Views
Last Modified: 2016-10-16
Hello all and thanks for your time and expertise.  I'm still green at powershell and I've been tasked with removing multiple users from an AD group.  Please note I've already created a .txt file with all of the samaccountnames of the relevant users.  
The affected users are all in the same OU and that's where I exported the list of login names from.  
Would really appreciate if someone could provide me the syntax for this kind of operation.  Thanks.
0
Comment
Question by:pendal1
  • 2
4 Comments
 
LVL 30

Expert Comment

by:pgm554
ID: 41816270
Why not just use Solarwinds?
It's free and it will do what you need.

http://www.solarwinds.com/free-tools/active-directory-admin-tools-bundle/
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points (awarded by participants)
ID: 41816280
To remove list of users from GroupA use following code..
Import-Module Activedirectory
$Users = GC C:\userlist.txt
Remove-adgroupmember -Identity "GroupA" -Members $Users

Open in new window


Or

Import-Module Activedirectory
GC C:\userlist.txt | %{Remove-adgroupmember -Identity "GroupA" -Members $_}

Open in new window

Sample C:\userlist.txt
UserA
UserB
UserC

Open in new window

0
 
LVL 6

Expert Comment

by:sAMAccountName
ID: 41816300
Embrace Powershell.  Abandon third party apps.

This is rudimentary but works:
$List = Get-Content "C:\Users\jdoe\Desktop\input.txt" 
Foreach ($Item in $List){Remove-ADGroupMember -Identity GroupName -Member $Item}

Open in new window

0
 
LVL 40

Expert Comment

by:Subsun
ID: 41845506
Options provided should resolve user queries.
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
Loops Section Overview
Screencast - Getting to Know the Pipeline

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question