Solved

Powershell remove-aduser in bulk issue

Posted on 2014-04-24
2
3,688 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
[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 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40020487
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
ID: 40020542
This worked! Thanks!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

729 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