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

 
 
 
 
 
(10)
3,172 times
Add to favorites
System Center
3/10/2012
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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 = $oldComputer.name  
      
      	$stream.WriteLine($computername)
      }
      
      $stream.close()
      
      
      
      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?
      
      -Brett
    • 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. 
      
      Thanks...Eric 
    • 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
      running.'.
      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
         tiveDirectory.Management.Commands.GetADComputer
      
      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?
      Thanks
    • 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.
      
      Thanks!
      
      Eric
  • 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: http://technet.microsoft.com/en-us/library/bb632595.aspx 
      
      The specific task you will want is Delete Obsolete Client Discovery Tasks: http://technet.microsoft.com/en-us/library/bb632879.aspx 
  • how to run the script
    2 Posts | Last post June 20, 2012
    • Hello,
      Please am new to scripting and I will like to use this script to remove old computers from my SCCM server.I saved the script as .vbs and when i run it i get errors. Also when i copied the script to powershell i get error that "The specified module 'ActiveDirectory' was not loaded because no valid module file was found in any module directory"
      Please help me on this. I will really appreciate if i can be tutored on how to run this script.
      
      Thanks.
    • Hi There,
      
      You need to save it as a .ps1 file on your SCCM server to be able to be run in the console.
      
      For the Active Directory module, you can follow the instructions on my blog about installing the RSAT (Remote Server Administration Tool) and enabling the Active Directory Module for Windows PowerShell.
      
      http://www.discoposse.com/index.php/2011/12/13/multi-environment-powershell-console/
      
      Thanks,
      
      Eric