Solved

delete old users in AD

Posted on 2014-09-24
3
76 Views
Last Modified: 2014-11-18
Hi,

Need code to delete left (old) users from our domain. I have list of the old users' usernames to run the script for it.

Do not need to delete home folders that sits on SAN or NAS or file servers as I have a different code to delete their shares and home folders.

So all I need is a code to delete their AD accounts in our domain.
Can you please help?

thanks
0
Comment
Question by:kuzum
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40341077
gc file.txt | % {Remove-ADUser -Identity $_ -whatif}

Open in new window

The above code has a whatif so you can validate the action, the command below is the actual run

gc file.txt | % {Remove-ADUser -Identity $_}

Open in new window


That will remove each user from your list from AD
0
 
LVL 29

Expert Comment

by:becraig
ID: 40341081
before running, be sure to run:
import-module ac*

This will load the active directory module so the command can run.
0
 
LVL 17

Expert Comment

by:Learnctx
ID: 40341108
Add -confirm:$false unless you want to have to confirm the deletions. By default the cmdlet will request confirmation unless you override it.

Remove-ADUser -Identity $_ -confirm:$false
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
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 …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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