Solved

Remove multiple users from an AD group with powershell

Posted on 2016-09-26
4
35 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
Comment Utility
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)
Comment Utility
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 5

Expert Comment

by:sAMAccountName
Comment Utility
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
Comment Utility
Options provided should resolve user queries.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now