Remove from SCCM all Computers that are not in Active Directory

This script will verify all the computers inside an SCCM collection and check if they exist in active directory, if the machine doesn't exist it will delete it from SCCM and if the machine is in active directory but is disable it will write out a warning message

SCCM_Cleanup.ps1
 
 
 
 
 
(0)
301 times
Add to favorites
System Center
7/29/2019
E-mail Twitter del.icio.us Digg Facebook
  • Why is it deleted SCCM objects when found in AD
    2 Posts | Last post August 14, 2019
    • I have ran ISE both as Administrator and as my elevated credentials that has DA rights.  Both ways deleted objects in SCCM cause it says it cannot find the object in AD but, I validated the objects are there and not disabled.  I ran this from the SCCM server and from site code.
      I have set collection and log location
      
      With DA Rights ad object does exist in AD
      WARNING: Computer Computer1 not found in AD removing from SCCM
      VERBOSE: Invoking cmdlet 'Get-CMDevice'
      VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE RestoreClientResourceID = 16778780
      VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE RestoreClientResourceID = 16778780. Processed 0 results in 00:00:00.
      VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE SourceClientResourceID = 16778780
      VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE SourceClientResourceID = 16778780. Processed 0 results in 00:00:00.
      VERBOSE: Performing the operation "Remove" on target "Device: Name="DM11029"".
      VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE SourceClientResourceID = 16778780
      VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE SourceClientResourceID = 16778780. Processed 0 results in 00:00:00.
      VERBOSE: Start: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE RestoreClientResourceID = 16778780
      VERBOSE: Finish: Execution of WQL query: SELECT * FROM SMS_StateMigration WHERE RestoreClientResourceID = 16778780. Processed 0 results in 00:00:00.
      VERBOSE: Delete() object 'SMS_R_System.ResourceId=16778780'
      
      
    • Hi Captain
      
      Do you have more than 1 domain?
      Please add the -Server parameter and type the domain name
      Example:
      (Get-ADComputer -Identity $_ -ErrorAction Stop -Server MyDomain1.com).Name 
      
      And let me know the results
      Thanks
      Regards