Delete AD multiple user accounts using PowerShell

Deleting bulk user accounts made easy using Powershell.

We have tested the below script in Windows Server 2008 R2 AD infrastructure.
Users are present in Sales OU as shown below.

Create a txt or csv file with user SamAccountName as shown below.

Below is the Powershell Script to delete the bulk users from AD.

The Script data is below, copy the below text into Notepad, and save it as RemoveAccount.ps1
Import-Csv .\Remove.txt | foreach-object {
remove-aduser -identity $_.SamAccountName -confirm:$false }

To run the script on AD:
  • Run PowerShell as Administrator
  • Change to the location where you have placed the Script and the TXT/CSV file.
  • Now run the script. Type “.\RemoveAccount.ps1”

Accounts are deleted as shown below.

7 thoughts on “Delete AD multiple user accounts using PowerShell

  1. I am having an issue getting this to run correctly, I have a csv but i get an error:Remove-ADUser : Cannot validate argument on parameter 'Identity'. The argumentis null. Supply a non-null argument and try the command again.At line:1 char:65+ import-csv delete.csv | foreach-object { remove-aduser -identity <<<< $_.identity } + CategoryInfo : InvalidData: (:) [Remove-ADUser], ParameterBindi ngValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ eDirectory.Management.Commands.RemoveADUser

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s