This script will remove computer objects from SCCM that no longer exist in your defined Active Directory System Discovery locations.  The LDAP paths defined in the Active Directory System Discovery method will be loaded into the script directly from SCCM, so there is no risk of making an error in providing this information to the script.

The Active Directory module included with Remote Server Administration Tools may be used, or alternatively Active Roles Management Shell.  Depending on the size of the SCCM environment this script may take up to 2 hours or more to run (for 15,000 - 20,000 computer objects).

This type of cleanup activity is especially useful when trying to obtain accurate client saturation statistics.


#    Remove computer objects from SCCM that no longer exist in an Active Directory location  
#    defined within the SCCM Active Directory System Discovery configuration. 
# NOTE: 
#    The SCCM Console must be present and connected via PowerShell, one time, on the system 
#    where this is executed. 
#    powershell-connecting-to-configuration-manager/ 
#    Powershell 4.0 or higher 
#    Active Roles Management Shell for Active Directory -OR- Active Directory Cmdlets (RSAT) 
#    System Center Configuration Manager Cmdlet Library 
        # SCCM Site Code (3-digit code) [string] 
            $CMSiteCode = "P01" 
        # SCCM Primary Server ( [string] 
            $CMPrimaryServer = "" 
        # Collection name to clean up (typically 'All Systems' or 'All Workstations') [string] 
            $CleanCollection = "All Systems" 
        # Active Directory global catalog server ( [string] 
            $GCServer = "" 
        # Use the Active Directory Module (RSAT) instead of Active Roles Mgmt Shell [boolean] 
            $UseRSATModule = $False 
# No need to edit below this line 
        # Please use the download button above to retreive the full code.