Solved

delete old users in AD

Posted on 2014-09-24
3
80 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
[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
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
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…

688 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