Remove old Active Directory computers from SCCM

A common issue in IT organizations is that the removal of computer objects is not done regularly. While I've presented scripts for removing old computer accounts from Active Directory, I've recently had to extend the removal of legacy computers into other systems such as SCCM.Bec

3.9 Star
7,000 times
Add to favorites
System Center
E-mail Twitter Digg Facebook
Sign in to ask a question

  • deleted from where
    1 Posts | Last post June 23, 2016
    • I want to be sure this script only removes the computer from SCCM.  not AD correct?  
  • Script Information
    1 Posts | Last post September 16, 2013
    • Just a note, Script has been tested on Windows 8 & 8.1 and 2012, all 3 are compatible after you remove the Properties * from the get-adcomputer query. Or at least in our environment it was needed. 
  • Query About Forest Wide
    1 Posts | Last post July 08, 2013
    • Hello,
      First of all, thank you very much for you contribution!!.
      Second, i made a modificaion to only list the computers into a text file.
      # Environment setup 
      # Import the ActiveDirectory module to enable the Get-ADComputer CmdLet 
      Import-Module ActiveDirectory 
      $old = (Get-Date).AddDays(-45) # The threshold for what we consider to be old (current set as 45 days) 
      $stream = [System.IO.StreamWriter] "c:\lista.txt" 
      # Find the computers in Active Directory which are "old" 
      $oldComputers = Get-ADComputer -Filter {PasswordLastSet -le $old} -Properties * 
      ForEach ($oldComputer in $oldComputers) 
          # Select the computer(s) 
          $computername = $  
      my question is.... is this ... or how can we do this script forest wide?
      Thanks so much in advance.
  • Compatibility
    3 Posts | Last post June 10, 2013
    • Do you know if this will work with SCCM 2012 as well?
    • Hi Brett,
      That's a great question. I wish that I had an answer for you but unfortunately I haven't put together a 2012 edition lab yet so I can't say for sure. If I do find out I will be sure to let you know. 
    • Script seems to run as expected in SCCM 2012 SP1.
  • Clear machines with ADWS?
    1 Posts | Last post June 08, 2013
    • I have an environment where we do not have AD web services running which I believe this script uses, is there a way of clearing out "old" machines that are not in AD but are still in the SCCM database as a device?
  • Modification to Script?
    2 Posts | Last post April 25, 2013
    • Is there a way to export the "dead/old" computers into a txt file?
    • Disregard.  I ran the script and it shows it in the output pane anyways.  Great script.
  • Error running script
    1 Posts | Last post March 15, 2013
    • Im getting this error:
      Get-WmiObject : Invalid parameter
      En línea: 12 Carácter: 14
      +     $resID = Get-WmiObject -computername $SCCMServer -query "select resourceID f ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
          + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  • Error when running Script
    1 Posts | Last post February 05, 2013
    • Hi Eric,
      This looks like exactly what I am looking for but I am having trouble running this Script. I am new to scripting and I'd appreciate if you can give me some assistance with this. I am running into the below error when I run this. Also, Do I need to edit the script and enter my SCCM info or will it prompt me for that while running within power shell? Thank you Eric.
      WARNING: Error initializing default drive: 'Unable to find a default server with Active Directory Web Services
      Get-ADComputer : Unable to find a default server with Active Directory Web Services running.
      At C:\Users\Administrator\Downloads\RemoveOldComputersFromSCCM.ps1:10 char:31
      + $oldComputers = Get-ADComputer <<<<  -Filter {PasswordLastSet -le $old} -Properties *
          + CategoryInfo          : ResourceUnavailable: (:) [Get-ADComputer], ADServerDownException
          + FullyQualifiedErrorId : Unable to find a default server with Active Directory Web Services running.,Microsoft.Ac
      Get-WmiObject : Invalid parameter
      At C:\Users\Administrator\Downloads\RemoveOldComputersFromSCCM.ps1:17 char:24
      +     $resID = Get-WmiObject <<<<  -computername $SCCMServer -query "select resourceID from sms_r_system     where name
       like `'$computername`'" -Namespace "root\sms\site_$sitename"
          + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
  • What is the difference between OLD and DEAD computer?
    2 Posts | Last post November 16, 2012
    • What is the difference between OLD computer account and DEAD computer?
    • Hi Ihab,
      That's a great question. It's really just a semantic issue. OLD and DEAD are effectively the same thing. It's just a matter of how you'd prefer to label the machines which are aged out.
  • criterios de borrado
    2 Posts | Last post July 14, 2012
    • Necesito borrar del SCCM las maquinas que fueron borradas del AD. Este script hace esto???
      Sino es asi... en base a que parametros el script borra la maquina del SCCM que son "viejas" en el AD ??
    • This script only removes the "old" accounts by passing the computer name into the SCCM query. 
      For removing dead computers you can use the maintence tasks from SCCM which you will find here: 
      The specific task you will want is Delete Obsolete Client Discovery Tasks: 
1 - 10 of 11 Items