Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove multiple users from an AD group with powershell

Posted on 2016-09-26
4
Medium Priority
?
45 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 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

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

704 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