Solved

Remove multiple users from an AD group with powershell

Posted on 2016-09-26
4
44 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

623 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