Close Menu
    Facebook X (Twitter) Instagram
    Saturday, October 11
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»configmgr»SCCM Configmgr 2012 Powershell script How to delete multiple packages applications Driver packages what else ?

    SCCM Configmgr 2012 Powershell script How to delete multiple packages applications Driver packages what else ?

    Eswar KonetiBy Eswar KonetiJuly 23, 5:41 am5 Mins Read configmgr 11,389 Views
    Share
    Facebook Twitter LinkedIn Reddit

    Long Ago,wrote a powershell script to add packages,applications,driver packages,Boot Images etc to selected Distribution Points,more information http://eskonr.com/2014/02/configmgr-2012-updated-powershell-script-add-packages-applications-drivers-to-distribution-point/

    As Configmgr admin,we will be doing some maintenance cleanup activities monthly or quarterly for applications,packages,drivers ,collection etc.I will write another post  on ,how to identify the packages which are not used from longer period by Configmgr clients.

    Removing single package from console is straight forward .Right click on package and click delete.This process takes few steps asking to go through the prompt to answer or delete directly.

    I have collected several packages with different package types like applications,driver packages,SUP packages etc using the SQL quires based on the usage and i decided to delete all of them. How do delete all ?

    Search each package where do they reside in console and delete one by one manually ? If you have no better job than this,then yes,you can of course go with manual method to identify where they reside in Console and delete it .

    Powershell gives so much flexible to perform most of the configmgr jobs with single command line.

    I wrote a powershell script-looks like very lengthy since the commands for package,application type,SUP,image are different and i have used several if conditions to check if the package really deleted from console or not not before it write the result to output file .

    This script basically take the information from the txt file , what you supplied and based on the package type (like switch case here),it will jump to the specific category and perform the deletion.

    What is required before you run the script  ?

    1.Enough permissions to delete the content from Configmgr console

    2. Get list of all package names (script is written based on its Name instead of Package ID) either from Console or SQL database along with its package Type.

    3. create excel or notepad with format shown below:

    packages1

     

    do some excel work to replace the space with comma(,) and save it .

    output of CSV should look like this :

    packages2

     

    You don’t require Excel to be installed on the computer to run the script .Notepad is enough to read for Powershell.

    Powershell Script :

    #######################################################################
    #Name: Remove multiple packages ,applications,drivers,Images etc from Configmgr 2012
    #Author: Eswar Koneti
    #Date Created:23-July-2014
    #Avilable At:www.eskonr.com

    #######################################################################

    #Import Module
    $CMModulepath=$Env:SMS_ADMIN_UI_PATH.ToString().Substring(0,$Env:SMS_ADMIN_UI_PATH.Length -  5)+"\ConfigurationManager.psd1"
    import-module $CMModulepath -force
    #Change the site Code
    CD PRI:
    #Change output File Location to store the results
    $Outputpath='C:\Users\eswar\Desktop\Removed-packages.txt'
    #Change the input filename ,make sure you supply the information in correct format

    Import-Csv C:\Users\eswar\Desktop\Remove-packages.csv |`
    ForEach-Object {
    $PackageType = $_.PackageType
    $PackageName = $_.PackageName
    # For Packages

                If($PackageType -eq "Package")
    {
    #Check if the supplied package exist in CM12
    if ( Get-CMPackage -Name "$PackageName")
    {
    Remove-CMPackage -Name  "$PackageName" -Force
    #Check if the supplied package deleted or not from CM12
    if (!( Get-CMPackage -Name "$PackageName"))
    {
    "Package " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "Package " +  $PackageName + " "+ "Not Deleted ,Fix the problem and delete manually " | Out-File -FilePath $Outputpath -Append
    }
    }
    }

    #For Applications

                If($PackageType -eq "Application")
    {
    #Check if the supplied Application exist in CM12
    if ( Get-CMApplication -Name "$PackageName")
    {
    Remove-CMApplication -Name  "$PackageName" -Force
    #Check if the supplied Application deleted or not from CM12
    if (!( Get-CMApplication -Name "$PackageName"))
    {
    "Application " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "Application " +  $PackageName + " "+ "not Deleted ,Fix the problem and delete Manually " | Out-File -FilePath $Outputpath -Append
    }
    }

                    }

    #For Driver Packages
    If($PackageType -eq "Driver")
    {
    #Check if the supplied Driver Package exist in CM12
    if ( Get-CMDriverPackage -Name "$PackageName")
    {
    Remove-CMDriverPackage -Name  "$PackageName" -Force
    #Check if the supplied Driver Package deleted or not from CM12
    if (!( Get-CMDriverPackage -Name "$PackageName"))
    {
    "Driver " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "Driver " +  $PackageName + " "+ "not Deleted ,Fix the problem and delete Manually " | Out-File -FilePath $Outputpath -Append
    }

                        }
    }

    #For BootImages

                If($PackageType -eq "BootImage")
    {
    #Check if the supplied Boot Image exist in CM12
    if ( Get-CMBootImage -Name "$PackageName")
    {
    Remove-CMBootImage -Name  "$packagename" -Force
    #Check if the supplied Boot Image deleted or not from CM12
    if (!( Get-CMDriverPackage -Name "$PackageName"))
    {
    "BootImage " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "BootImage " +  $PackageName + " "+ "not Deleted ,Fix the problem and delete Manually " | Out-File -FilePath $Outputpath -Append
    }
    }
    }

    #For OSImage
    If($PackageType -eq "OSImage")
    {
    #Check if the supplied OS Image exist in CM12
    if ( Get-CMOperatingSystemImage -Name "$PackageName")
    {
    Remove-CMOperatingSystemImage -Name "$packagename" -Force
    #Check if the supplied OS Image deleted or not from CM12
    if (!( Get-CMOperatingSystemImage -Name "$PackageName"))
    {
    "OSImage " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "OSImage " +  $PackageName + " "+ "not Deleted ,Fix the problem and delete Manually " | Out-File -FilePath $Outputpath -Append
    }

                       }
    }

    #For SUPPackages
    If($PackageType -eq "SUP")
    {
    #Check if the supplied SUP Package exist in CM12
    if ( Get-CMSoftwareUpdateDeploymentPackage -Name "$PackageName")
    {
    Remove-CMSoftwareUpdateDeploymentPackage -Name  "$packagename" -Force
    #Check if the supplied SUP Package exist in CM12
    if (!( Get-CMSoftwareUpdateDeploymentPackage -Name "$PackageName"))
    {
    "SUP " +  $PackageName + " "+ "Deleted " | Out-File -FilePath $Outputpath -Append
    }
    else
    {
    "SUP  " +  $PackageName + " "+ "not Deleted ,Fix the problem and delete Manually " | Out-File -FilePath $Outputpath -Append
    }
    }
    }

    }

     

     

    To know more about Configmgr Powershell cmd-lets,refer http://technet.microsoft.com/en-us/library/jj821831(v=sc.20).aspx

    If you have any difficulties with above script,download it via TechNet Gallery: http://gallery.technet.microsoft.com/SCCM-Configmgr-2012-dfbe62e6

    CM12 Configmgr 2012 delete packages from txt file List of packages remove PoSH Powershell PowerShell Script remove applications Remove packages SCCM 2012
    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

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

    June 30, 7:01 pm

    Optimize Your Intune Workflow with a Powerful Browser Extension

    March 22, 10:39 am

    10 Comments

    1. Pingback: Remove multiple package in SCCM – Damberg Online

    2. Sankara on July 12, 2016 5:37 AM

      Thanks for providing this script, simple but really helpful. It seems the script stops continuing after CD command, is there any continue statement to be given for this to be followed?

      Reply
    3. SeemonRaj S on July 5, 2016 2:09 AM

      Hi,

      Will this delete the package source files too?

      Thanks,
      Seemon

      Reply
      • Eswar Koneti on July 5, 2016 8:35 AM

        Hi Seeman,
        No, it won't delete package source files, just only package from console.

        Thanks,
        Eswar

        Reply
        • SeemonRaj S on July 8, 2016 11:15 PM

          Hi Eshwar,

          Thank you for the response. Just would like to see if you have any suggestion for me. I am intending to delete the packages along with source files.

          Thanks,
          Seemon

          Reply
          • Eswar Koneti on July 8, 2016 11:35 PM

            Hi Seemonraj,
            You can extend the script to get the Content location path for the particular package before deleting the package from console and after the package is deleted from console ,delete the source files also.
            The script should do something like below:
            Get the package location source files for the particular package and store it in variable
            Delete the package from console
            delete the source files that stored in first step.

            Thanks,
            Eswar

            Reply
            • SeemonRaj S on July 10, 2016 9:50 PM

              This was really helpful. Thanks again Eshwar.

              Reply
    4. PhiBu on April 8, 2016 2:06 PM

      I´ve written a guide on how to clean up the Database within SCCM.
      I used your script as part of it.
      I also made a simple way of inputting the Data into the CSV via Notepad++ and some rregex usage.
      If you like, you can have a look here:

      http://www.ritter-nerd.de/2016/sccm-treiber-datenbank-aufraeumen-teil-2/

      Reply
      • Eswar Koneti on April 15, 2016 11:47 PM

        thanks and appreciate it PhiBU

        Reply
    5. Gary on December 12, 2015 2:36 AM

      Hey, this just saved me a large amount of time today. THANK YOU! - @gwblok

      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.

     

    Loading Comments...