Solved

delete old users in AD

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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