[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Powershell remove-aduser in bulk issue

Posted on 2014-04-24
2
Medium Priority
?
4,173 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

656 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