Solved

delete old users in AD

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

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 28

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 16

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

Free Trending Threat Insights Every Day

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

24 Experts available now in Live!

Get 1:1 Help Now