dipopo
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}
Why is this script not working:
:\> gc c:\usersremove.txt | % {get-aduser -filter 'Name -like $_ '} | ft SamAccountName | % {remove-aduser $_ -confirm:$false}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!!!
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?
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.
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
Please see the EE guidelines on grading..
http://support.experts-exchange.com/customer/portal/articles/481419
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..
ASKER
gc C:\removesamaccount.txt | remove-aduser -confirm:$false
and the above is the samaccountsname in a text file.