Solved

Remove multiple users from an AD group with powershell

Posted on 2016-09-26
4
39 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 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article runs through the process of deploying a single EXE application selectively to a group of user.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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