Solved

Powershell remove-aduser in bulk issue

Posted on 2014-04-24
2
3,039 Views
Last Modified: 2014-04-24
I have this short script taken from a site that allows me to remove in bulk numerous accounts in one shot.

The problem is I am getting this error:

Remove-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and
try the command again.
At C:\userdel\userdel.ps1:2 char:24
+ remove-aduser -identity <<<<  $_.SamAccountName -confirm:$false}
    + CategoryInfo          : InvalidData: (:) [Remove-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.RemoveADU
   ser


The script is here:

Import-Csv .\delete.txt | foreach-object {
remove-aduser -identity $_.SamAccountName -confirm:$false}

The format of delete.txt is:

user1
user2
user3
user4
...

What do I have wrong? It looks like its not picking up the $_.SamAccountName variable but I dont know why?

Thanks!
0
Comment
Question by:smyers051972
2 Comments
 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
Comment Utility
since you say your input is a text file there is no header so .SamAccountName is not needed.

if the file has headers be sure the top row is named:  SamAccountName

Provided the value in the text file is the samaccountname.


or else just use
 gc .\delete.txt | foreach-object {
remove-aduser -identity $_ -confirm:$false}

Open in new window

0
 
LVL 1

Author Closing Comment

by:smyers051972
Comment Utility
This worked! Thanks!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

728 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

10 Experts available now in Live!

Get 1:1 Help Now