Link to home
Start Free TrialLog in
Avatar of dipopo
dipopoFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Piping into remove-aduser

Hi Experts,

Why is this script not working:

:\> gc c:\usersremove.txt | % {get-aduser -filter 'Name -like $_ '} | ft SamAccountName | % {remove-aduser $_ -confirm:$false}
Avatar of dipopo
dipopo
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Also tried this but same result, must be missing something.

gc C:\removesamaccount.txt | remove-aduser -confirm:$false

and the above is the samaccountsname in a text file.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dipopo

ASKER

Error generated is:

Remove-ADUser : Cannot find an object with identity: 'bracken
                                                      ' under: 'DC=xxxxxxxxx,DC=xxx'.
At line:1 char:46
+ gc C:\removesamaccount.txt | % {remove-aduser <<<<  "$_" -confirm:$false}


but running the command with the samaccountname works!

remove-aduser bracken -confirm:$false

hence what is the difference as the only thing that is different is one is piped and the other is not!!!!
Do you have any trailing space in the text file data?
Avatar of dipopo

ASKER

Thank you Subsun this worked wonderfully!

gc c:\usersremove.txt | % {get-aduser -filter 'Name -like $_ ' | remove-aduser -confirm:$false}

I'm baffled though as I tried this before and it did not work....oh well, all is well that ends well.

Thanks again.
Nice..  BTB any particular reason for the B grade?

Please see the EE guidelines on grading..
http://support.experts-exchange.com/customer/portal/articles/481419
Avatar of dipopo

ASKER

Opps my bad, anyway I can change it?
No problem.. I think only Mod's can change it.. you may use Request Attention option to create a request with Mod's..