Close Menu
    Facebook X (Twitter) Instagram
    Sunday, October 12
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»CM2012»Powershell script to delete computer records from SCCM

    Powershell script to delete computer records from SCCM

    Eswar KonetiBy Eswar KonetiNovember 19, 10:02 pm3 Mins Read CM2012 25,858 Views
    Share
    Facebook Twitter LinkedIn Reddit

    Recently I had a requirement to create a PowerShell script to read text file/CSV for list of clients (servers mainly) and check if they appear in SCCM if so delete them ,track the information into log file for reference.

    There could be various reasons why do you want to delete computer record from SCCM and for that, you can either delete the record directly from the console or use scripting to do it for you.

    One of of the reason for me to create this script is ,to help the team to delete the server records from SCCM after they decom immediately using task scheduler. Why immediate ? can't I wait for default maintenance tasks to remove the computer object after it becomes inactive or aged ? well ,it does . Once the computer record is disabled in AD or not online for X days ,It becomes inactive . Once the client is inactive and fall into the range X days to match site maintenance tasks  then it will be removed from SCCM database . When I leave these decom clients for deletion using site maintenance tasks ,these decom servers do appear in compliance reports and client health reports in SCCM and because of this ,the client health dashboard doesn’t appear in good status.

    So ,this script will help guys to pipe the computer records into text file (as input ) and run the script or can schedule the script to run weekly once or so. The script will read the text file ,check if the computer record exist in database or  not ,if not ,out-put to log ,if exist ,delete the entry ,out-put results to log and this loop continue until the last line read in text file.

    Removing a device client manually deletes the client record from the Configuration Manager database. Typically, you should not use this action unless it is for troubleshooting scenarios. If you delete the client record and the Configuration Manager client is still installed and communicating with Configuration Manager, Heartbeat Discovery recreates the client record the Configuration Manager database, although the client history and any previous associations are lost.

    To delete computer record from SCCM if exist ,I used inbuilt SCCM powershell cmdlet called Remove-CMDevice -name $comp –force .

    You can download Powershell script to delete computer records from SCCM via TechNet .

    You can use this script as schedule task to run on weekly basis .All you need is ,pipe the computer records into the notepad and let the script run for you automatically.

    image

    auto deletion of client configmgr delete resource Powershell powershell to delete client record remove client Remove-CMDevice remvove computer using script SCCM schedule tasks scripting
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    Export Microsoft Entra ID User Authentication Methods to CSV using PowerShell & Microsoft Graph API

    August 13, 2:08 pm

    SCCM SQL Report – Compare Installed Apps on TWO Different Computers

    July 13, 10:35 am

    Exporting Intune Win32 Apps with All Properties Using PowerShell and Microsoft Graph

    June 30, 7:01 pm

    12 Comments

    1. MelQ on July 15, 2019 7:06 AM

      Thank you for this! This is exactly what I needed!

      Just a note, I had to change 1 small thing. Regarding line 17, in my environment, $env:SMS_ADMIN_UI_PATH resolves to C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386; however, ConfigurationManager.psd1 is located in C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386 (so one level up in the bin folder instead of i386). So, I hardcoded the path for the import-module command on line 17. All else worked exactly how I needed in my environment without changing anything.

      Reply
      • Eswar Koneti on July 23, 2019 1:10 PM

        Thanks for the update MelQ. Appreciate it. With the changing of the configmgr and how they install folder structure ,i did not update the post for a while.

        Regards,
        Eswar

        Reply
        • Dee on August 27, 2021 2:22 AM

          Hi Eswar,
          I believe I messaged you already but have not gotten a response. The link to the script is not valid anymore. Did you have a copy of the script where you can post it to?

          Thanks,
          Dee

          Reply
          • Eswar Koneti on September 2, 2021 1:06 AM

            Hi,
            it is available in github https://github.com/eskonr/MEMPowered/blob/master/Technet%20Gallery/Powershell%20Delete%20computer%20records%20from%20SCCM.zip

            Thanks,
            Eswar

            Reply
    2. Yash Reddy on May 31, 2017 1:45 AM

      I just checked that we can use "task scheduler" for automating process. i need help with file name input (network location & file name) and changing site name/site code.

      Reply
      • Eswar Koneti on June 4, 2017 8:03 PM

        you can edit the powershell script ,change the sitecode . Follow the blog post http://eskonr.com/2014/08/sccm-configmgr-2012-powershell-script-cleanup-duplicate-obsolete-and-outdated-computers-via-scheduled-tasks/

        Regards,
        Eswar

        Reply
        • Sunil on June 8, 2017 5:27 PM

          Hi Eswar, Can we use the script on the machine which doesnt have configuration manager console?

          Reply
          • Eswar Koneti on July 7, 2017 1:19 AM

            Hi Sunil,
            Yes but you need to connect to remote server to load the configuration manager module to load the powershell cmdlets.

            Regards,
            Eswar

            Reply
            • G Vinay on June 4, 2019 6:19 PM

              Hi Eswar.

              This is Vinay.. i am supporting SCCM 2012 and as well 2016. I got your script and i am unable to run this script i am getting error message. I need to use this script to my environment.

              The String is missing the terminator:”.
              +CategoryInfo :Parsererror” (:) [] ParentContainserrorRecordException
              +FullyQualifiedErrorID :TerminatorExceptedAtEndofString

              Reply
        • Rajesh on November 28, 2019 7:07 AM

          Hi Eswar,
          This is a nice script and works well for me. If I want to delete a specific list of machines that start with XYZ, how can I pass the like condition in this script?

          Reply
          • Eswar Koneti on November 30, 2019 3:38 AM

            Hi,
            You can create a collection (query) to list devices that start with xyz (xyz%) and delete the members from the collection would be easier.

            Thanks,
            Eswar

            Reply
    3. Yash Reddy on May 31, 2017 1:28 AM

      Need Help in modifying script according to our environment,
      1. Where to mention sitename and site code in the script
      2. I want to run this script daily...where to do that
      3. Can i use a network location to read the txt files.
      4. There is a network folder in which all the text files will be saved with name "mm-dd-yyyy.txt", in this case if i automate the script to run daily...how can i input the filename?

      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-2025 Eswar Koneti, All rights reserved.

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