Feature image

SCCM: Updating Existing Software Update Groups via PowerShell



Author: Nawaz kazi

Every month, SCCM administrators face a recurring challenge: they need to modify certain existing Software Update Groups (SUGs), marking them as baseline SUGs or adjusting them for compliance, among other tasks. This routine, while essential, can be time-consuming, potentially eating into valuable time that could be better spent on other critical tasks.

What if this could be done more simply, though?

Enter PowerShell. With the right script, what once took hours can now be accomplished in mere minutes.

In this blog post, we’ll delve into a PowerShell script designed to automate the process of adding software updates to an SCCM SUG directly from a CSV file. Let’s dissect this solution step by step, integrating code snippets for a comprehensive understanding.

1. Laying the Groundwork with the SCCM Module

Our journey begins by ensuring PowerShell can interact with SCCM. This is achieved by loading the SCCM module for PowerShell:

Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')

2. Identifying the Right SCCM Site

To operate effectively within the SCCM environment, our script first discerns the SCCM site code. This critical piece of information steers the script to the appropriate SCCM site:

$siteCode = (Get-WmiObject -Namespace "root\SMS" -Class SMS_ProviderLocation).SiteCode
Set-Location $siteCode":"

3. Setting the Stage in Excel

Before diving into the updates, we established a platform in Excel to document our results. A new workbook is readied, and specific headers are set to capture outcomes:

$excelApp = New-Object -comobject Excel.Application
$excelApp.visible = $True
$workbook = $excelApp.Workbooks.Add()
$worksheet = $workbook.Worksheets.Item(1)
$worksheet.Cells.Item(1, 1) = "Update Title"
$worksheet.Cells.Item(1, 2) = "Status"

4. The Operational Core: Processing Updates

Our script then taps into the CSV file, extracting software update titles:

$updates = Import-Csv -Path E:\Pathto\updatetitle.csv | ForEach-Object { $_.UpdateTitle }

5. Interacting with the SUG

The heart of this script revolves around efficiently processing each software update and integrating it into the desired SUG. Here’s how it unfolds:

For every update title fetched from the CSV, the script initiates a series of checks:

foreach ($updateTitle in $updates) {
    $sug = Get-CMSoftwareUpdateGroup -Name $sugName

6. Verifying the SUG:

The script first attempts to retrieve the specified Software Update Group. If it doesn’t exist, the absence is noted in Excel.

if ($sug) {...} else {
    $worksheet.Cells.Item($row, 1) = $updateTitle
    $worksheet.Cells.Item($row, 2) = "SUG Not Found"

7. Locating the Software Update:

If the SUG exists, the script searches for the software update by its title. If the update isn’t found, this is recorded in Excel.

$update = Get-CMSoftwareUpdate -Fast | Where-Object {$_.LocalizedDisplayName -eq $updateTitle} | Select-Object -First 1

8. Checking the Update’s Status:

Once the update is located, the script checks if its content has been downloaded. If the update isn’t downloaded, this status is noted in Excel. If the update is ready, it’s added to the SUG, with the outcome documented in Excel.

if ($update.IsContentProvisioned -eq $true) {
    Add-CMSoftwareUpdateToGroup -SoftwareUpdateName $update.LocalizedDisplayName -SoftwareUpdateGroupName $sug.LocalizedDisplayName
    $worksheet.Cells.Item($row, 1) = $updateTitle
    $worksheet.Cells.Item($row, 2) = "Added to SUG"
} else {
    $worksheet.Cells.Item($row, 1) = $updateTitle
    $worksheet.Cells.Item($row, 2) = "Not Downloaded"

9. Iterating for Each Update:

After processing each update, the script moves to the next row in Excel, readying itself for the next software update.


10. Recording Results in Excel:

Excel acts as the result repository. As each software update is processed, its status — whether it was added to the SUG, not downloaded, or not found — is recorded in an Excel spreadsheet. This provides a clear, visual report for administrators, ensuring transparency and traceability.

2023 10 16 09 52 34

Full Script can be found on GitHub


This script underscores the transformative power of automation in SCCM management. By seamlessly navigating through Software Update Groups and ensuring every update is accurately placed, SCCM administrators can now focus on more strategic tasks, leaving the repetitive to PowerShell.

For those eager to further amplify their SCCM expertise, stay tuned. Exciting updates and insights are on the way.

Leave a Comment

Your email address will not be published. Required fields are marked *