none
Deleting multiple computer accounts at once. RRS feed

  • Question

  • Hello.

    I've been searching around the internet for months now, looking for at solution for this.

    I'm looking for a way, to delete multiple computer accounts from Active Directory, from a txt file with ONLY computername, not full path, on Windows Server 2008 R2 and Windows Server 2012 R2.

    I've found multiple soultions but none of them seem to work the way I want it to. For example I've found several cmd commands to delete accounts from a txt file, but it requires that I write the full path to the object, with OU and everything, so it's just the same as searching for every computer manually and deleting, since they are located in different OU's.

    I've found other commands to delete computer accounts, that have not been active for x number of weeks. This is NOT what I need. What I do is, I run a script to disable computers, and if no one have complained within 1 month, I want to delete them and only them, and not OTHER machines that are disabled.

    My script for disabling works perfectly and looks like this:

    @echo off
    set ComputerList="C:\list.txt"
    for /f "delims=" %%a in ('type "%ComputerList%"') do (
      echo Processing %%a ...
      dsquery computer -name "%%a" | dsmod computer -disabled yes
    )

    I've also seen people suggest using Powershell. I have basically no knowledge and experince with Powershell, so please provide an example if you suggest that.

    Thank you in advance.

    Wednesday, March 25, 2015 11:32 AM

Answers

  • >    dsquery computer -name "%%a" | dsmod computer -disabled yes
     
    replace dsmod with "dsrm -subtree -noprompt -c"
     
    -subtree is only required if the computer hosts shared printers that are
    published to Active Directory.
     
    :)
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    • Proposed as answer by Mr XMVP Wednesday, March 25, 2015 1:06 PM
    • Marked as answer by Vivian_WangModerator Thursday, April 2, 2015 1:29 AM
    Wednesday, March 25, 2015 12:02 PM
  • You could do this with powershell

     
    Get-Content "textfile" | ForEach-Object {Get-ADComputer -Identity $_} | Remove-ADComputer -Confirm:$false

    The -confirm:$false stops ad promoting a are you sure warning. 

    In the text file each computer should be on a new line. 

    • Proposed as answer by Mr XMVP Wednesday, March 25, 2015 1:06 PM
    • Marked as answer by Vivian_WangModerator Thursday, April 2, 2015 1:29 AM
    Wednesday, March 25, 2015 12:14 PM

All replies

  • >    dsquery computer -name "%%a" | dsmod computer -disabled yes
     
    replace dsmod with "dsrm -subtree -noprompt -c"
     
    -subtree is only required if the computer hosts shared printers that are
    published to Active Directory.
     
    :)
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    • Proposed as answer by Mr XMVP Wednesday, March 25, 2015 1:06 PM
    • Marked as answer by Vivian_WangModerator Thursday, April 2, 2015 1:29 AM
    Wednesday, March 25, 2015 12:02 PM
  • You could do this with powershell

     
    Get-Content "textfile" | ForEach-Object {Get-ADComputer -Identity $_} | Remove-ADComputer -Confirm:$false

    The -confirm:$false stops ad promoting a are you sure warning. 

    In the text file each computer should be on a new line. 

    • Proposed as answer by Mr XMVP Wednesday, March 25, 2015 1:06 PM
    • Marked as answer by Vivian_WangModerator Thursday, April 2, 2015 1:29 AM
    Wednesday, March 25, 2015 12:14 PM
  • Thank you. These was exactly what I was looking for. Thank you so much.

    Have a nice day.

    Friday, March 27, 2015 1:56 PM