A few months ago I created a script that would assist ConfigMgr admins with cleaning up their Software Update Groups from expired and superseded Software Updates. Although this script needed manual interaction by selecting what Software Update Group to clean, specifying to keep the content or remove it, I think it was a huge help to the community. I was contact by a fellow named Merlijn who had made his own contributions to the script and it gave me some ideas. The first thing he did was to add the functionality to select only to clean Expired Software Updates. With this addition, administrators that are managing supersedence manually have more flexibility to control their environment. So I’ve decided to update the Clean-CMSoftwareUpdateGroup.ps1 script with his code, and made some alterations myself so that it can now be leveraged as a console extension to clean all of the Software Update Groups in four different ways. From the comments I received on the previous script, it occurred to me that the readers of this blog really wanted to automate this workflow in every way. You spoke and I listened, so I hereby bring you the updated version of this script, now as a console extension. Although I highlight the possibility to use this as a console extension, the script is built to be used in any manner that might suit the admin.

With this updated script, you now have the option to clean your Software Update Groups with the following criteria:

  • Expired and Superseded (Remove content)
  • Expired and Superseded (Keep content)
  • Expired Only (Remove content)
  • Expired Only (Keep content)

Download the console extension

You can download the console extension from the TechNet Gallery.

Install the console extension

There are two ways that you can install this console extension, either by running the Invoke-ToolInstallation.ps1 script that comes in the package, or by manually copying the content to it’s designated location and editing the XML file.

Automated installation

1. Download the zip-file from the TechNet Gallery and unpack it to e.g. C:\Temp\CleanSoftwareUpdateGroups. You should now have the following files in C:\Temp\CleanSoftwareUpdateGroups:

  • CleanSoftwareUpdateGroups.xml
  • Invoke-ToolInstallation.ps1
  • Clean-CMSoftwareUpdateGroups.ps1

2. Close the ConfigMgr console, open an elevated PowerShell console and run the following command to install the tool (Path parameter should point to a location where the script file will be stored, and the SiteServer parameter should be the name of the site server, e.g. a Primary Site server):

.\Invoke-ToolInstallation.ps1 -SiteServer CAS01 -Method Install -Path C:\Scripts -Verbose
131_4

3. Re-launch the ConfigMgr console.

Manual installation

1. Download the zip-file from the TechNet Gallery and unpack it to e.g. C:\Temp\CleanSoftwareUpdateGroups. You should now have the following files in C:\Temp\CleanSoftwareUpdateGroups:

  • CleanSoftwareUpdateGroups.xml
  • Invoke-ToolInstallation.ps1
  • Clean-CMSoftwareUpdateGroups.ps1

2. Close the ConfigMgr console and copy Clean-CMSoftwareUpdateGroups.ps1 from C:\Temp\CleanSoftwareUpdateGroups to e.g. C:\Scripts (it’s important that you place it in a non-temporary location, since the CleanSoftwareUpdateGroups.xml file will point to this location for referencing the script).
3. Edit the CleanSoftwareUpdateGroups.xml file on each of the lines (4 of them) that starts with <Parameters>, amend the parts specified in brackets (#), e.g. from:

-executionpolicy bypass -file #PATH# -SiteServer #SERVER# -ShowProgress -Verbose

to the following:

-executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer CAS01 -ShowProgress -Verbose

4. Go to <ConfigMgr console root directory>\XmlStorage\Extensions\Actions. You can get the path by running a PowerShell console and typing:

$env:SMS_ADMIN_UI_PATH

5. Create a directory in the Actions folder called:

  • 23e7a3fe-b0f0-4b24-813a-dc425239f9a2

6. Copy the CleanSoftwareUpdateGroups.xml file from C:\Temp\CleanSoftwareUpdateGroups to the directory recently created.
7. Re-launch the ConfigMgr console.

Using the Clean Software Update Groups console extension

Once you’ve successfully installed the console extension, you can launch it by right clicking on the Software Update Groups node in the Software Library node:

131_2

Once the script has done it’s magic, the end result of your Software Update Groups view could look like this:

131_3

Nickolaj Andersen
Principal Consultant and Enterprise Mobility MVP. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows deployments and Automation. In 2015 Nickolaj was awarded as PowerShell Hero by the community for his script and tools contributions. Author of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService and a frequent speaker at user groups.

(1511)

comments
  • Mathieu Aït Azzouzene
    Posted at 19:29 March 15, 2015
    Mathieu Aït Azzouzene
    Reply
    Author

    Thanks for this great extension. I still cannot believe it is not built in…
    Does this work for SCCM 2007?

    • Nickolaj
      Posted at 07:07 March 16, 2015
      Nickolaj
      Reply
      Author

      Hi Mathieu,

      Thank you for the kind words. Yeah, it’s a bit surprising to me as well. But I guess that they’ve chosen other priorities. As for if this tool works for 2007, to be frank, I’m not sure. But since the class names should be the same I tihnk it will. I guess you have to give it a shoot in a lab environment.

      Regards,
      Nickolaj

  • lordofmilk
    Posted at 00:55 March 16, 2015
    lordofmilk
    Reply
    Author

    very useful extension! thanks!

    • Nickolaj
      Posted at 07:07 March 16, 2015
      Nickolaj
      Reply
      Author

      Thank you!

  • Trevor
    Posted at 10:45 March 16, 2015
    Trevor
    Reply
    Author

    Another great tool! Isn’t it true that in ConfigMgr 2012 R2 there is a built-in process that removes the expired updates from the package source and the distribution points, once they have been removed from the SUGs? I guess your tool expedites that process?

  • Alan Dooley
    Posted at 11:22 March 16, 2015
    Alan Dooley
    Reply
    Author

    Thank you for this, I have been using your script for a couple of months but this just makes it even easier. Great work!

    • Nickolaj
      Posted at 19:09 March 16, 2015
      Nickolaj
      Reply
      Author

      Hi Alan,

      You’re most welcome, I hope it will simplify your life 😉

      Regards,
      Nickolaj

    • HK
      Posted at 17:10 March 19, 2015
      HK
      Reply
      Author

      Hi Alan,
      Does this script clean up all the expired updates from all the software update groups or do we need to specify the name of the update group to be cleaned

      Please advise.

  • Christian
    Posted at 14:00 March 16, 2015
    Christian
    Reply
    Author

    In this new version, is there still the option to only clean specific software update groups? There are some I’m responsible for and others that I’m not. Thanks!

    • Nickolaj
      Posted at 19:14 March 16, 2015
      Nickolaj
      Reply
      Author

      Hi Christian,

      Unfortunately not. You’d have to make use of the old script or extend the console yourself by using that script.

      Regards,
      Nickolaj

  • André
    Posted at 14:41 March 16, 2015
    André
    Reply
    Author

    Fantastic stuff! Where is the MVP-Award? 🙂

    • Nickolaj
      Posted at 19:14 March 16, 2015
      Nickolaj
      Reply
      Author

      Thank you André!

      You’d have to contact Microsoft regarding the MVP-award 😉

      Regards,
      Nickolaj

  • Bill
    Posted at 20:21 March 16, 2015
    Bill
    Reply
    Author

    Doesn’t seem to be working? I can see some red in the Powershell window that flashes up? Any logging? Process to diagnose?

    • Nickolaj
      Posted at 20:29 March 16, 2015
      Nickolaj
      Reply
      Author

      Hi Bill,

      How does your XML file look? What installation instructions did you follow?

      Regards,
      Nickolaj

      • Bill
        Posted at 20:37 March 16, 2015
        Bill
        Reply
        Author

        I used the automated installation. I was able to invoke the script from the PS command line (in the ISE) and it seems to be working interestingly enough.

        I think I see the problem in the .XML file looks like the script failed to set the siteserver name. I’ll correct that.

        • Nickolaj
          Posted at 12:22 March 20, 2015
          Nickolaj
          Reply
          Author

          Hi Bill,

          Great that you found the issue. Did you manage to get it working by correcting the server name?

          Regards,
          Nickolaj

          • Bill Dunn
            Posted at 13:04 March 20, 2015
            Bill Dunn
            Author

            I haven’t had an opportunity to retest, my distribution hierarchy is still recovering from the manual run I did that worked. Takes a LONG time to redistribute 40+ distribution packages when they are all triggered for redistribution at the same time, to 92 servers.

            That’s why I had a bit of a panic Monday when I realized what the script would actually do.

            Future enhancement request, throw in a switch so the script cleans up the sources for the deployment packages, but doesn’t trigger redistribution. I know in my situation and probably others are in the same boat we need to redistribute in a more controlled manner.

          • Nickolaj
            Posted at 15:43 March 20, 2015
            Nickolaj
            Author

            Hi Bill,

            I’ll take a note of your request and see what I can come up with in the near future, shouldn’t be that very hard to add such a switch to the script. I hope that you get your distributions up and running again.

            Regards,
            Nickolaj

  • Matt
    Posted at 15:37 March 17, 2015
    Matt
    Reply
    Author

    I am seeing this error when I run clean up script “You must provide a value expression on the right-hand side of the ‘-‘ operator. At C:\Scripts\Clean-CMSoftwareUpdateGroup.ps1:75 char:42

    Check the XML and verified right path and site server.

    Thoughts?

    • Nickolaj
      Posted at 12:20 March 20, 2015
      Nickolaj
      Reply
      Author

      Hi Matt,

      Could you please paste the content on row 75 from your script file?

      Regards,
      Nickolaj

    • Matt
      Posted at 18:08 March 20, 2015
      Matt
      Reply
      Author

      if ($CIID.CI_ID -notin $RemovedUpdatesList) {

  • Kevin Johnston
    Posted at 18:43 March 18, 2015
    Kevin Johnston
    Reply
    Author

    The script does not work for me either. I did the automated install. I have verified the .xml has the right settings.

    When I run it, I get a quick popup with red text and that is it.

    If I try to invoke Clean-CMSoftwareUpdateGroups.ps1″ -SiteServer HSC -ExpiredOnly -RemoveContent -ShowProgress -Verbose from my c:\scripts folder I just end up with
    >> on the screen

    Not sure what I am doing wrong. I have run the console as Administrator still same issue.

    • Nickolaj
      Posted at 12:15 March 20, 2015
      Nickolaj
      Reply
      Author

      Hi Kevin,

      Have you installed the console extension on your Primary Site server, or on a remote management system with the ConfigMgr console installed? Either way, in my opinion it should work. Could you try to launch the script manually with the specified parameters in CleanSoftwareUpdateGroups.xml?

      Regards,
      Nickolaj

      • Kevin Johnston
        Posted at 12:29 March 20, 2015
        Kevin Johnston
        Reply
        Author

        Hi nicklaj,

        I installed it on my Primary Site.

        As stated:
        If I try to invoke Clean-CMSoftwareUpdateGroups.ps1″ -SiteServer HSC -ExpiredOnly -RemoveContent -ShowProgress -Verbose from my c:\scripts folder I just end up with
        >>

        Is there a way to have the screen with the red text stop, so I can see what it is saying. As it only flashes for a quick second, I am only guessing.

        I will try to manually install the extension.

        One thing I did have an issue with the install because of Execution permissions. But I fixed that and it installed without issues with all the settings.

        • Nickolaj
          Posted at 12:32 March 20, 2015
          Nickolaj
          Reply
          Author

          Hi Kevin,

          Sorry I missed that part of your comment. Just to be clear, when executing a PowerShell script you need to have the “.\” symbols in front of the script file. Could you email me a screenshot perhaps? You’ll find my contact details in the menu of this blog.

          Regards,
          Nickolaj

          • Kevin Johnston
            Posted at 13:15 March 20, 2015
            Kevin Johnston
            Author

            I am not sure if everyone will have a brain malfunction like me… but I somehow decided that #SERVER# meant site code.

            So everything is fixed after setting it up properly. I was able to run it in the console without issues.

            Just remember that #SERVER# does not mean site code 🙂

            Thanks Nickolaj for pointing out the obvious!!

          • Nickolaj
            Posted at 15:41 March 20, 2015
            Nickolaj
            Author

            You’re welcome Kevin 🙂

            Regards,
            Nickolaj

  • hk
    Posted at 17:04 March 19, 2015
    hk
    Reply
    Author

    If we click Remove expired content, is it going to ask specific software update group to get cleaned up or would it clean every thing automatically.

    Thanks

    • Nickolaj
      Posted at 12:12 March 20, 2015
      Nickolaj
      Reply
      Author

      Hi HK,

      As it’s described in the blog post, this script will go through all of your Software Update Groups with various outcome due to the selection you make in the right click menu.

      Regards,
      Nickolaj

  • Baard
    Posted at 19:14 March 21, 2015
    Baard
    Reply
    Author

    Hi!

    Brilliant tool, now if i only could make it work…
    Did the automated install, have verified that all files are where they should be and that the content of the xml-file is corrrect.
    However nothing is happening when running the tool, besides the PowerShell window popping up and closing just a few Seconds later, no visible text that i can see.
    Have run the console as Admin, still no difference.

    Any ideas?

    • Nickolaj
      Posted at 08:10 March 22, 2015
      Nickolaj
      Reply
      Author

      Hi Baard,

      Could you send me an email with the XML file and a screenshot where you the script manually? You can simply open the the XML file and copy the whole script line with the parameters and values and paste it into an elevated PowerShell console (assuming you’ve browsed to the correct folder where the script file exists).

      Regards,
      Nickolaj

      • Baard
        Posted at 10:38 March 23, 2015
        Baard
        Reply
        Author

        *facepalm*

        Although reading the documentation several times, i still managed to mistake SiteServer for Site code…
        My excuse is that your example servername resembles out site code…

        Updated the xml with servername and now things are running along as they are meant to 😀

        Thanks 🙂

        • Nickolaj
          Posted at 14:57 March 23, 2015
          Nickolaj
          Reply
          Author

          You’re welcome Baard, and I’m glad that you managed to solve the issue. Although, to be fair, my example SiteServer name is five characters and a SiteCode can only be 3 characters 😉

          Regards,
          Nickolaj

          • Baard
            Posted at 15:58 March 23, 2015
            Baard
            Author

            Oy, i’m blond.
            Dætts maj eksjuice!

            🙂

          • Nickolaj
            Posted at 16:05 March 23, 2015
            Nickolaj
            Author

            Haha, you’re excused 😉

  • Sal
    Posted at 09:28 March 22, 2015
    Sal
    Reply
    Author

    I am seeing this error when I run clean up script

    You must provide a value expression on the right-hand
    At C:\Temp\CleanSoftwareUpdateGroups\Clean-CMSoftware
    + if ($CIID.CI_ID – <<<< noti
    + CategoryInfo : ParserError: (:) [], Pa
    + FullyQualifiedErrorId : ExpectedValueExpression

    • Nickolaj
      Posted at 09:58 March 22, 2015
      Nickolaj
      Reply
      Author

      Hi Sal,

      What version of PowerShell are you running? You can type $host in the console.

      Regards,
      Nickolaj

  • Nick Palmer
    Posted at 17:51 March 25, 2015
    Nick Palmer
    Reply
    Author

    Hi,
    I’m trying to follow this process and I also get the following error when I run the script manually (I did the automated install process but it didn’t seem to update the XML file correctly, but did put the XML file and script in the right place. So I edited the XML file and then retried from the SCCM console but that still failed so I just tried running the command manually)

    .\Clean-CMSoftwareUpdateGroups.ps1 -SiteServer TOPANGA -RemoveContent -ShowProgress -Verbose

    Where TOPANGA is the name of my primary site server

    You must provide a value expression on the right-hand
    At C:\Temp\CleanSoftwareUpdateGroups\Clean-CMSoftware
    + if ($CIID.CI_ID – <<<< noti
    + CategoryInfo : ParserError: (:) [], Pa
    + FullyQualifiedErrorId : ExpectedValueExpression

    My power shell version is 2.0.

    • Nickolaj
      Posted at 18:08 March 25, 2015
      Nickolaj
      Reply
      Author

      Hi Nick,

      I just read up on the In and NotIn conditions and it seems they were introduced in version 3.0, this is from the about documentation:

      The In operator was introduced in Windows PowerShell 3.0

      So in your case you’d have to install WMF 3.0 on your Primary Site.

      Regards,
      Nickolaj

      • Nick Palmer
        Posted at 20:03 March 25, 2015
        Nick Palmer
        Reply
        Author

        Nickolaj,

        I thought about doing that but I’ve read several really bad things about installing the WMF 3.0 on a Windows 2008 R2 SCCM 2012 SP1 server. Seems like WMF 3.0 causes lots of problems.

        Maybe this was an early release of WMF 3.0?

        Nick

  • Anton Masyan
    Posted at 09:36 March 30, 2015
    Anton Masyan
    Reply
    Author

    Great work. Thx, Nickolaj.

  • Kevin Johnston
    Posted at 18:29 March 30, 2015
    Kevin Johnston
    Reply
    Author

    So after I ran the Expired Only (remove content) it seems like it cleaned up things, but it did not delete the SUPs. Not a big deal to delete them, but they do show up with red X’s.

    Just wondering if this script was supposed to delete the SUPs as well as the content.

    Maybe I missed something?

  • RV
    Posted at 18:57 April 6, 2015
    RV
    Reply
    Author

    Just wondering if it is possible to edit the xml file and point to required software update group to clean up instead of all at once. I need this because we manage few software update groups and our workstations team manage theirs, i cannot cleanup all groups at once.

  • NJ
    Posted at 19:00 April 7, 2015
    NJ
    Reply
    Author

    Great tool! Any chance this can be used to clean up Software Update Compliance Baselines?

    • Nickolaj
      Posted at 06:52 April 9, 2015
      Nickolaj
      Reply
      Author

      Hi NJ,

      Could you elaborate a bit more on that, please? I’m not sure I understand what you mean with Software Update Compliance Baselines. As of now the tool only cleans up Software Update Groups, in fact all of them even if they’re only used for compliance check or deployed to devices.

      Regards,
      Nickolaj

  • Jake
    Posted at 21:44 April 20, 2015
    Jake
    Reply
    Author

    Very nice, thank you Nickolaj for your continuous contributions to the ConfigMGR community.

  • Shilpy Grover
    Posted at 05:20 May 1, 2015
    Shilpy Grover
    Reply
    Author

    Thanks for the utility. However, if I want to know what are the contents of Expired and Superseded(Remove&Keep), How I can do that? ALso what if I want to uninstall the console extension?

    Thanks,
    Shilpy

    • Alex
      Posted at 08:36 August 9, 2016
      Alex
      Reply
      Author

      Hello,

      You can install by modifying the below:
      -Method Install to -Method UnInstall

  • Thierry Frutieaux
    Posted at 17:46 May 21, 2015
    Thierry Frutieaux
    Reply
    Author

    Hello Nickolaj,

    Great Tools it works like a charm.
    Save me few Head ache to deals with cleaning expired updates.
    Thank you very much.

    Best regards

    Thierry

    • Nickolaj
      Posted at 07:17 May 22, 2015
      Nickolaj
      Reply
      Author

      Hi Thierry,

      You’re most welcome. Let me know if you have any questions or suggestions when using it 🙂

      Regards,
      Nickolaj

  • Shilpy
    Posted at 04:47 May 26, 2015
    Shilpy
    Reply
    Author

    Thanks for the utility. However, if I want to know what are the contents of Expired and Superseded(Remove&Keep), How I can do that? ALso what if I want to uninstall the console extension?

    Thanks,
    Shilpy

  • ben
    Posted at 07:36 August 4, 2015
    ben
    Reply
    Author

    Hi Nickolaj,

    i like the idea to have it in GUI instead of your old scripted version.
    However, it’s not working for me..
    I used automated installation, in the XML the -SiteServer parameter was just empty, so i corrected it.

    When i run
    c:\scripts\Clean-CMSoftwareUpdateGroups.ps1 with the parameters of the XML everyhting is running fine.

    When i goto to my console and Click the Icon it opens a PS window and closes again, can’t see if anything is displayed in there.
    I installed it on my primary site server.

    Regards
    Ben

    • Steve Whitcher
      Posted at 21:38 August 26, 2015
      Steve Whitcher
      Reply
      Author

      Ben, and others who see the PS window open and close right away when running the cleanup extension:

      The install script has an issue in parameter validation. If, like me, you first tried running the installer script w/o any parameters, it would have appeared to run without actually installing the extension. Even though it didn’t seem to do anything, the script DID edit the xml file to include the parameters you provided (namely, none.) The next time you run the script, actually including the appropriate parameters, the script would NOT edit the xml file, because the bits of text it looks to replace aren’t in the file anymore. So, the script will now install the console extension but with the xml file missing key details. When you try to run the extension from the SCCM console, it will open a powershell window, flash a red error very quickly, then disappear.

      The solution is to delete the scripts and xml file then re-extract them from the original zip file. This time, don’t run the invoke-toolinstallation.ps1 script without parameters, and it should install a working copy of the console extension.

      Steve

  • Joel Fernandes
    Posted at 04:58 August 27, 2015
    Joel Fernandes
    Reply
    Author

    Hello Nick,

    The tool looks awesome, but i am not able to use it, I tried installing the Automated as well as the manual option, the tool gets installed,
    but when i try to launch it from the ConfigMgr console nothing happens, a power shell window open for couple of seconds it closes, there is some error red color text on the power shell which i am not able to read.

    Can you please help if i am missing out something here.

    • Steve whitcher
      Posted at 07:16 August 28, 2015
      Steve whitcher
      Reply
      Author

      Joel, did you see my reply to Ben above?

      Did you by chance run the script once without any parameters, before re-running it work the correct Params? If so, that would explain why you are getting the brief powershell window and error.

      • Joel Fernandes
        Posted at 08:12 August 28, 2015
        Joel Fernandes
        Reply
        Author

        Hey Steve i was able to fix the issue, thank you so much.
        After running the scripts it deleted all the expired updates but when i check my Software Update Groups in the Console it still shows all the expired groups .

  • Ben
    Posted at 12:04 August 28, 2015
    Ben
    Reply
    Author

    Steve, thank you very much!
    It’s working now 🙂

  • Austin WongCarter
    Posted at 16:46 October 21, 2015
    Austin WongCarter
    Reply
    Author

    Hi Steve, I really liked your script, but didn’t want to run it on all of my Software Update Groups at once. So, I took your old script for just one group and made the same type of console extension using that. Would you like it so you can distribute it?

    -Austin

  • Pesho NT
    Posted at 10:56 November 22, 2015
    Pesho NT
    Reply
    Author

    Hello Nikolaj,
    Yor script caught attention to my environment architect 🙂
    This is unbelievably efficient tool. Thank you for this stuff!
    However i have a suggestion or more like a bug report which will be nice to be adjusted in the script. If you have time for this.
    — at step RemoveContet the script checks for content and attempts removal from sources folder. However if there are multiple MS updates and it reported unable to delete for some of them it will not continue with the others and if they are truly downloaded they will be left available in the source location. So will you please make it continue even though the files were not successfully deleted?
    — It will be great if there is a logging option because I was not able to use commands like “Out-file” or “> filename.log”
    Once again thank you for the great work!

    • Nickolaj
      Posted at 10:19 November 25, 2015
      Nickolaj
      Reply
      Author

      Hi Pesho,

      Thanks for the bug report! I’ll see if I have the time to update this script, right now there’s a lot going on 🙂

      Regards,
      Nickolaj

  • zeddy
    Posted at 22:44 December 6, 2015
    zeddy
    Reply
    Author

    Hello Nikolaj,

    I am trying to remove all updates from the SUG via sccm 2012 Powershell module. Since there’s no direct cmdlet refereeing to updates deletion within the SUG I noticed that people refer to WMI class SMS_AuthorizationList which they query.
    However, I am struggling a bit with how to query those CI_ID’s or updates when I got the desired SUG already selected like below:

    PS U01:\> Get-WmiObject -Namespace root\sms\site_U01 -Class SMS_AuthorizationList | Where-Object -Property LocalizedDisplayName -EQ ‘TEST patch gremoroup’ | Format-List -Property CI_ID,updates

    CI_ID : 100664251
    updates :

    This SUG consists of three updates and the CI_ID result doesn’t apply to the CI_ID’s that are actually in the queried SUG.
    Updates property is empty…

    Could you please at least point me in the right direction? Am I looking in the correct WMI class as the software update properties are empty in this one I guess. Actually, is it possible to remove the content from the SUG via PowerShell from the specific SUG and those updates aren’t expired or superseded?
    Many thanks in advance

    Regards,

    Zeddy

  • Craig
    Posted at 22:43 December 23, 2015
    Craig
    Reply
    Author

    Hi There,

    One recommendation I would make is the ability to log the output each time the tool is run. When I run the tool none of the SUGs I have with a yellow icon (denoting they have superseded content) turn green after the tool is finished. Studying the output of the command may help but it disappears to quickly.

  • seb
    Posted at 21:19 January 13, 2016
    seb
    Reply
    Author

    very nice tool thanks a lot!
    I didn’t expect it to re distribute all the content of the software update package to all the DP though 🙂
    I’ll second a delay or manual option to do it later.
    (I used the Expired and Superseded (Remove content))
    thanks

  • Merlijn
    Posted at 16:25 February 9, 2016
    Merlijn
    Reply
    Author

    Hi Nikolaj,

    Been a while 🙂

    Got some feedback on your latest version of the script. I’ve found a logic error in the queries that determine whether an updates is either superseded, expired or both.

    As you know, I’m a fan of deleting only expired updates. This is where your new version took me by surprise: it wouldn’t find any expired updates to clean 🙁 Yet there were many to be found. The error was soon found in line 84 of the script. A software update can never have IsExpired set to 1 AND isSuperseded set to 0. If it’s expired, it’s also always superseded. Makes sense when you think about it for a minute. So I changed the query to check for both values being 1.

    $Query = “SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND SU.IsExpired = 1 AND SU.IsSuperseded = 1”

    Next problem: now the query on line 91 is exactly the same as the one I just edited. Yet, the expected result would be all expired AND superseded updates. Not really. We want to find and clean all updates that are either marked as expired or superseded. So this is an ‘OR’ situation. This results in the following query:

    $Query = “SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND (SU.IsExpired = 1 OR SU.IsSuperseded = 1)”

    Note the brackets around the ‘OR’ statement. They need to be grouped as otherwise the ‘AND’ operation is processed first.

    One more note, our first query (line 84) can be shortened to evaluate the IsExpired property only. Because if it’s expired, it’s also superseded. You’ll never find one that has IsExpired = 1 AND IsSuperseded = 0

    $Query = “SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND SU.IsExpired = 1”

    With these changes, I got the script working perfectly for my environment. And super fast! Excellent job on improving the efficiency!

    I’ll email you the edited version of your script.

  • Baard Hermansen
    Posted at 19:20 February 10, 2016
    Baard Hermansen
    Reply
    Author

    According to https://msdn.microsoft.com/en-us/library/hh949121.aspx, RelationType 6 = Superseded and RelationType 1 = Bundled.
    Why limit to RelationType 1, when apparently you get all superseded updates when querying for RelationType 6?

    In my environment querying for RelationType 1, i get several updates that are either IsExpired = 0 or IsSuperseded = 0.
    If i Query RelationType = 6, i get only IsSuperseded = 1 and IsExpired either 1 or 0.

    The major difference, is that when using RelationType = 1 gives more results than RelationType = 6 and also a lot more IsDeployed = 1.

    Does it matter if IsDeployed is 1 or 0 when deleting updates?

  • tom smith
    Posted at 15:28 April 20, 2016
    tom smith
    Reply
    Author

    Hello,

    I wonder if you could help me, I have this working fine on my old sccm console but I cant get it working on a new build of sccm on another domain. I have set it up exactly the same way and the extension is there to run on the software update groups but it doesn’t seem to do anything…

    the windows pops up and then closes very quickly… I cant see any errors just says “no changes detected will not update”

    but there are expired up[dates still in the software update groups.
    My xml file looks ok (has the site server name)

    I set it up using the 1st method you suggested using powershell and it has created the directory and placed the xml file inside.

    any help would be appreciated

  • tom smith
    Posted at 15:51 April 20, 2016
    tom smith
    Reply
    Author

    update**
    after further investigation, it seems to be the expired + superseded (remove content) extension that doesn’t work…
    if I run the superseded (remove content) that gets rid of the expired updates, so there must be something wrong with just one part of it….

    • Baard Hermansen
      Posted at 08:07 April 21, 2016
      Baard Hermansen
      Reply
      Author

      See previous comments about the Query not being correct: Superseeded updates are also expired.

    • Nickolaj
      Posted at 09:20 April 21, 2016
      Nickolaj
      Reply
      Author

      I thought that I’ve updated the file in the Gallery, but it doesn’t seem like it. On row 90, replace with the following:

      $Query = “SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND (SU.IsExpired = 1 OR SU.IsSuperseded = 1)”

      Regards,
      Nickolaj

  • I Am Sir Ask a lot
    Posted at 01:21 May 11, 2016
    I Am Sir Ask a lot
    Reply
    Author

    This console extension no longer works for me in SCCM 1511. Processes all of the SUGs then it just goes away.

  • tm
    Posted at 09:08 May 11, 2016
    tm
    Reply
    Author

    hello,

    still cant get this to work for “expired + superseded (remove content)” … i have altered the powershell script (C:\scripts\Clean-CMSoftwareUpdateGroups.ps1) on line 90 to read:

    $Query = “SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND SU.IsExpired = (1 AND SU.IsSuperseded = 1)”
    }

    any ideas?

  • tom
    Posted at 09:11 May 11, 2016
    tom
    Reply
    Author

    does anyone have the complete amended script ?

  • tom smith
    Posted at 09:23 May 11, 2016
    tom smith
    Reply
    Author

    This is my xml script in c:\temp:

    xml version=”1.0″?>

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer servername -Option ExpiredSuperseded -RemoveContent -ShowProgress -Verbose

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer servername -Option ExpiredSuperseded -ShowProgress -Verbose

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer servername -Option ExpiredOnly -RemoveContent -ShowProgress -Verbose

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer servername -Option ExpiredOnly -ShowProgress -Verbose

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer LUTSRVSCCMPS1 -Option SupersededOnly -RemoveContent -ShowProgress -Verbose

    DefaultHomeTab

    ContextMenu

    AdminUI.CollectionProperty.dll

    Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources

    AdminUI.UIResources.dll

    Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources

    SUM_Update

    “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”

    -executionpolicy bypass -file “C:\Scripts\Clean-CMSoftwareUpdateGroups.ps1” -SiteServer LUTSRVSCCMPS1 -Option SupersededOnly -ShowProgress -Verbose

    • Nickolaj
      Posted at 10:12 May 11, 2016
      Nickolaj
      Reply
      Author

      Hi Tom,

      Have you downloaded the amended script from TechNet Gallery? It was recently updated with the fixes to the WQL query.

      Regards,
      Nickolaj

  • tom
    Posted at 10:29 May 11, 2016
    tom
    Reply
    Author

    yes sorry you are correct, i just downloaded the new script and all is working now

    thanks for your help

    • Nickolaj
      Posted at 22:00 May 11, 2016
      Nickolaj
      Reply
      Author

      You’re most welcome, I’m glad it’s working as expected now.

      Regards,
      Nickolaj

  • Bill Dunn
    Posted at 15:47 May 31, 2016
    Bill Dunn
    Reply
    Author

    Loving the Script use it a lot, thanks for the latest update. Can I make a humble request for another feature. Add the ability to also remove updates that no have a “0” for required. Removing them “0” required from the software update groups is easy in the console that’s just a search criteria and edit membership its rather more tricky to hunt them down among the distribution packages.

  • Arnie
    Posted at 09:35 June 16, 2016
    Arnie
    Reply
    Author

    Hello Nickolaj, awesome script, it works like a charm!

    I would like to ask you for a thing. Is there a way to alter this script the way that this right click would be applicable to a specific SUG, instead of the “Software Update Groups” on the left menu?

    The reason is simple – I would like to clean just a particular/single SUG, not all of them at once.

    Thank you beforehand.

  • E Williams
    Posted at 13:23 July 4, 2016
    E Williams
    Reply
    Author

    Hello Nickolaj, great script and console idea. May I ask a dull question, does the ‘Remove Content’ option delete the stored files in the source folder or is it the distribution packages that is deleted? or both? Trying to find a way to weed out what is not required in the source folder.

  • Bill Dunn
    Posted at 20:46 July 18, 2016
    Bill Dunn
    Reply
    Author

    Figured out the Query to find updates that are not required by any machine, might I humbly request you consider a future revision adding an option to clear these as well.

    SELECT SU.CI_ID FROM SMS_SoftwareUpdate AS SU JOIN SMS_CIRelation AS CIR ON SU.CI_ID = CIR.ToCIID WHERE CIR.RelationType = 1 AND SU.NumMissing = 0

  • Craig
    Posted at 03:48 July 27, 2016
    Craig
    Reply
    Author

    Dies the latest script work in 1511?

    • Nickolaj
      Posted at 06:46 July 29, 2016
      Nickolaj
      Reply
      Author

      Hi Craig,

      Yes, it works well with ConfigMgr Current Branch (1511, 1602 and 1606) as far as I’ve seen. There should not be any fundamental changes between ConfigMgr 2012 R2 (and SP1) and Current Branch releases that affects this script.

      Regards,
      Nickolaj

    • ben
      Posted at 06:52 July 29, 2016
      ben
      Reply
      Author

      Hi Craig,

      i can also confirm that it’s working in 1511,1602 and 1606.

      Regards
      Ben

  • Ben
    Posted at 01:30 October 17, 2016
    Ben
    Reply
    Author

    Your a superstar Craig for creating this.
    Going to save me more time!

  • XV
    Posted at 22:49 October 25, 2016
    XV
    Reply
    Author

    I keep getting the Error Unable to determine Site Code
    I verified and my site code is correct.

    Error message below from ISE

    Cannot validate argument on parameter ‘SiteServer’. The “Test-Connection -ComputerName $_ -Count 1 -Quiet” validation script
    for the argument with value “AK1” did not return a result of True. Determine why the validation script failed, and then try the command again.
    + CategoryInfo : InvalidData: (:) [Clean-CMSoftwareUpdateGroups.ps1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Clean-CMSoftwareUpdateGroups.ps1

    I set the computer name to the server of my SCCM and then I got the error of

    WARNING: Unable to determine Site Code

    Please help.

    Thanks!

    • XV
      Posted at 21:38 November 10, 2016
      XV
      Reply
      Author

      Nvm I fixed my own issue. Great scripts!

      • Nickolaj
        Posted at 08:59 November 25, 2016
        Nickolaj
        Reply
        Author

        Perfect!

  • Brad
    Posted at 21:32 October 26, 2016
    Brad
    Reply
    Author

    Hi,
    This looks great. However I’m trying to use it to clean up two Primary Servers and it keeps saying “Unable to save changes to . Can you advise what could be causing this?

    It runs through groups where no changes are required, but as soon as it hits the first group requiring a clean I get:

    Performing the Operation “Clean ‘1’ updates on target “SUG name”
    Unable to save changes to “SUG name”

    It then falls over and stops processing anymore. It does this as I said at the first group it comes across that requires the removal of content, so I’m actually getting nothing done. I haven’t seen it successfully do a clean yet.

    Any help greatly appreciated.

  • Leave a Reply