Close Menu
    Facebook X (Twitter) Instagram
    Tuesday, May 20
    X (Twitter) LinkedIn
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»CM2012»SCCM Configmgr 2012 Powershell script cleanup duplicate obsolete and outdated computers Via Task Scheduler

    SCCM Configmgr 2012 Powershell script cleanup duplicate obsolete and outdated computers Via Task Scheduler

    Eswar KonetiBy Eswar KonetiAugust 19, 2:11 pm3 Mins Read CM2012 6,123 Views
    Share
    Facebook Twitter LinkedIn Reddit

    This post is continuation to my previous post on how to clean outdated computers from configmgr Database. More info refer , http://eskonr.com/2014/03/sccm-configmgr-2012-delete-duplicate-obsolete-records-etc-using-collections/

    Through this post,i will show you to create Powershell script cleanup duplicate obsolete and outdated computers Via Task schedule that deletes the computers from specific collections to maintain configmgr database healthy.

    In my previous blog,we have seen how to create collections for duplicate,obsolete,computers not contacted to domain during X days with hardware inventory older than 30 days etc.

    Note: if you are imaging the computers frequently ,you may see many duplicate/obsolete computers are you are required to cleanup those entries at regular intervals.

    Creating collections is nice but how frequent do you clean these entries ? keep checking once in week or once in month to delete the entries from database to have healthy environment and high success ratio on client health when your boss ask for client health statistics?

    There are configmgr Maintenance tasks that does the cleanup job for you like delete inactive,aged inventory data etc based on what task you enable. More about Maintenance tasks,refer http://eskonr.com/2012/01/configmgr-sccm-2012-site-maintenance-tasks/ and default settings for maintenance tasks http://support.microsoft.com/kb/2897050

    Through this post,i will show how to create powershell script to do the removal of computer records from specific collections (you can have many collections that contains out dated computers with different criteria) and empty the collection on scheduled basis.

     

    I have captured few lines of code from David blog http://www.david-obrien.net/ to get site code,site server name etc instead of providing them manually.

    Download the script from TechNet Gallery http://gallery.technet.microsoft.com/SCCM-Configmgr-2012-1446ec07

    Script function: It takes the collectionIDs as input parameter what you supply while running the script,check if the collection Exist ,check if the collection is not empty  and then perform removal of computer Objects.

    Before removal of computer objects ,script will write computer objects to txt file for reference incase you need check later.

    After you download the script,put it in either share folder or on local server.

    PS:You don't have to make any changes to the script ,just get the collection's which you want to cleanup.

    Create Task scheduler with recurring weekly or monthly at your convenience,get help from http://windows.microsoft.com/en-sg/windows/schedule-task#1TC=windows-7 .

    After you create Task scheduler,open the properties of Task and go to Action Tab,select the Actions ,click on Edit.

    image

    For program,/Script: type PowerShell.exe ,and for Arguments (Optional): type -command "& 'G:\SCCM Tools\delete-resources-from-collection.ps1' 'PRI0001E' ,'PRI00020'

    where 'G:\SCCM Tools\delete-resources-from-collection.ps1: is powershell script what we created earlier and PRI0001E,PRI00020 are the collections that i have to cleanup. If you have more collections ,just append the existing command like with ,’collectionID’.

    Actions Tab:

    image

    Make sure you run the task with right permissions on the database .you can change the account name to run the task from General Tab:

    image

    run the task,wait until it finishes. Go back your script location,you will see .txt file created with script ran date:

    image

    The txt file contains list of computers which are removed from the specific collection.

    Hope if helps for someone who wants to keep database active without outdated Clients ;).

    If you want to know what causes the client become Inactive ,refer http://www.david-obrien.net/2014/04/12/configure-client-activity-settings-configmgr/

    Cleanup computers CM12 Collections Configmgr 2012 delete obsolete Maintenance tasks PowerShell Script SCCM 2012 script Task scheduler
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Optimize Your Intune Workflow with a Powerful Browser Extension

    March 22, 10:39 am

    Migrate Microsoft 365 Updates from SCCM/MECM to Intune for Co-Managed Devices

    February 11, 9:50 pm

    Monitoring Endpoint Security Applications with SCCM ConfigMgr SQL

    October 11, 8:48 pm

    7 Comments

    1. Anon on August 17, 2023 12:54 AM

      Link to script doesn't exist anymore

      Reply
      • Eswar Koneti on September 7, 2023 7:30 PM

        Hi,
        you can use follow this blog post to download the scripts https://eskonr.com/2021/02/did-you-miss-to-download-your-samples-from-technet-gallery-here-is-how-you-can-do-it/

        Thanks,
        Eswar

        Reply
    2. Bruce on August 19, 2016 2:01 AM

      Have you ran the script to delete computers from x Collection recently? Trying to figure out why it's not working for me.

      "PS D:\Scripts> .\Delete_Computers_From_Collection.ps1 nt1000a2
      Method invocation failed because [System.Management.Automation.PSInternalMemberSet] does not contain a method named
      'delete'.
      At D:\Scripts\Delete_Computers_From_Collection.ps1:63 char:10
      + $comp.psbase.delete()
      + ~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (delete:String) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound"

      Reply
      • Eswar Koneti on August 19, 2016 8:42 AM

        I can check and let you know if anything is missing in the script.
        What version of CM are you running?

        Regards,
        Eswar.

        Reply
        • Bruce on August 19, 2016 9:01 AM

          Latest and greatest release version 1606

          Reply
          • Eswar Koneti on August 19, 2016 9:14 AM

            Alright. I will test and keep you posted.

            Regards,
            Eswar

            Reply
            • Andrew on January 11, 2017 10:58 PM

              I am having the same issue, and I am on 1602.

              Reply

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2024 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.