?
Solved

Powershell remove-aduser in bulk issue

Posted on 2014-04-24
2
Medium Priority
?
3,905 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 2000 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

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

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

801 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