Author Posts

September 8, 2015 at 10:58 am

$Computers = Get-Content D:\Scripts\Computers.txt -ReadCount 0
foreach ($Computer in $Computers)

Remove-ADComputer -Identity $Computer -Confirm: $false


Need output of this on a text file Plz help urgent.

September 8, 2015 at 11:05 am

Please don't put "urgent" on posts. Everyone here is a volunteer and will try to help as best they can, but we aren't paid consultants – we have jobs also, and must focus on those first. If something is urgent, you should consider hiring a consultant.

Look at the help for the Out-File cmdlet. It should be of some use.

September 8, 2015 at 11:19 am

Sorry Don, I just had to do something quickly, Thats why use urgent, sorry about that, Tried out-file but cant get the out put in the text can you help please

September 8, 2015 at 11:27 am

What did you try?

September 8, 2015 at 11:50 am

$Computers = Get-Content D:\Scripts\Computers.txt -ReadCount 0
foreach ($Computer in $Computers)

Get-Adcomputer -Identity $Computer |Remove-ADComputer -Identity $Computer -Confirm: $false |Out-File C:\Users\xx\pp.txt


Tried this as well, not working 🙁

September 8, 2015 at 12:56 pm

Remove the -ReadCount parameter. It's not doing anything for you.

You have to be more explicit than "it's not working". That's really not helpful. What's not working? It's not deleting the computer accounts? Or you're not seeing output in your file?

By the way, if you check the help file for Remove-ADComputer, there is no output. And even if there were, you would only see the last entry since you are not using the pipeline and you are not using the -Append switch.

So what are you seeing and/or not seeing that has you stumped?

I hope you are testing this in a test environment first. PowerShell is a double-edged sword and AD is a good place to create a "career limiting move" if you don't know what you're doing.

September 8, 2015 at 1:42 pm

Thanks Bob for your reply, Yes its deleting the computer account but I cant see the output in the text file. I tried using Add-content as well but still no go.

And yes of course I am testing it on dev env only. 🙂

September 8, 2015 at 1:51 pm

OK, what are you putting into your Add-Content statement? Can you post your entire current script?

September 8, 2015 at 1:57 pm

$Computers = Get-Content D:\Scripts\Computers.txt -ReadCount 0
foreach ($Computer in $Computers)

Remove-ADComputer -Identity $Computer -Confirm: $false |Add-Content -Path C:\logs.txt


Thats what I am using now, Before that tried using out-file as well, Its deleting the Computer accounts but not generating the output in the text file. Can you please let me know where I am going wrong ?

Thanks in advance.

September 8, 2015 at 2:05 pm

As I mentioned above, there is no output from the Remove-ADComputer cmdlet and no -PassThru switch. So there is nothing in the pipeline for Add-Content to absorb. Pipeline's empty – no content.
You would have to add another line in your foreach block.

"Deleted $Computer" | Add-Content -Path .\logs.txt"

That's logging that you created, not any text from the Remove-ADComputer cmdlet.

September 8, 2015 at 2:24 pm

Thank you so much for your help Bob, Its really helpful. There is a lot to learn I know, Thanks once again.