Introduction
This PowerShell script retrieves and displays information about software update groups, deployment packages, and successful deployments in Microsoft Endpoint Configuration Manager (MECM). It provides a quick overview of the current state of software updates in your MECM environment.
Use Case
This script is helpful for:
- Monitoring Updates: Quickly checking the status of software update groups and deployments in MECM.
- Troubleshooting: Identifying potential issues with software update deployments by reviewing successful and failed deployments.
- Reporting: Generating a basic report of software update information for analysis or documentation.
Script
PowerShell
# Requires -RunAsAdministrator
$SiteCode = "<Your MECM Site Code>"
$ProviderMachineName = "<Your MECM Provider Machine Name>"
function Write-ColorLog {
param(
[string]$Message,
[string]$Color = "Cyan",
[switch]$Error
)
$timestamp = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
$logMessage = '{0}: {1}' -f $timestamp, $Message
if ($Error) {
Write-Host $logMessage -ForegroundColor Red
} else {
Write-Host $logMessage -ForegroundColor $Color
}
}
try {
# Connect to SCCM
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"
New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName -ErrorAction SilentlyContinue
Set-Location "$($SiteCode):\"
# List all Software Update Groups
Write-ColorLog "Listing all Software Update Groups..." "Yellow"
Get-CMSoftwareUpdateGroup | Format-Table Name, LastRefreshTime, NumberOfUpdates
# List all Deployment Packages
Write-ColorLog "`nListing all Deployment Packages..." "Yellow"
Get-CMSoftwareUpdateDeploymentPackage | Format-Table Name, PackageID, LastRefreshTime
# List successful deployments
Write-ColorLog "`nListing recent successful deployments..." "Yellow"
Get-CMSoftwareUpdateDeployment | Where-Object {$_.ErrorCode -eq 0} |
Select-Object AssignmentName, DateCreated, UpdateGroup | Format-Table
} catch {
Write-ColorLog "Error: $_" -Error
}
Set-Location $env:SystemDrive
Write-ColorLog "Process completed" "Green"
Explanation
- Colored Logging: The script defines a
Write-ColorLog
function to display messages with different colors for improved readability. - Connect to MECM: It imports the
ConfigurationManager
module and connects to the specified MECM site. - List Software Update Groups: It retrieves and displays all software update groups with their name, last refresh time, and the number of updates.
- List Deployment Packages: It retrieves and displays all deployment packages with their name, package ID, and last refresh time.
- List Successful Deployments: It retrieves and displays successful software update deployments with their assignment name, creation date, and associated update group.
- Error Handling: The script uses a
try-catch
block to handle potential errors during the process.
Outro
This script offers a convenient way to quickly gather information about software updates in your MECM environment. By using this script, administrators can easily monitor the status of software update groups, deployment packages, and deployments, facilitating proactive management and troubleshooting.
Tags
PowerShell, MECM, SCCM, Software Updates, Monitoring, Reporting, Automation, Scripting, Deployment Packages, Software Update Groups