Overview

This post provides a PowerShell script designed to create an SCCM package that enables verbose logging for Windows Update. Enhanced logging is crucial for diagnosing and troubleshooting issues related to Windows updates, and deploying this configuration through SCCM ensures consistent application across all managed systems.

Instructions

  1. Copy the provided PowerShell script to a location on your SCCM server.
  2. Modify the script variables such as $SiteCode and $PackageSourcePath to match your environment.
  3. Run the script in PowerShell to create the SCCM package.
  4. Distribute the package to the desired distribution points within SCCM.
  5. Monitor the deployment to ensure that verbose logging is enabled on all targeted systems.

What the Script Does

This PowerShell script automates the creation of an SCCM package that enables verbose logging for Windows Update. Verbose logging generates detailed logs that are invaluable for diagnosing and resolving update-related issues.

PowerShell Script

# Define Variables
$ScriptName = "Enable-Windows-Update-Logging"
$ScriptDescription = "Enables verbose logging for Windows Update to help diagnose update issues."
$PackageSourcePath = "C:\Scripts\$ScriptName"

# Load SCCM PowerShell Module
Import-Module "$($Env:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" -Force
$SiteCode = "YourSiteCode"
cd "$SiteCode`:"

# Check if a package with the same name exists and delete it
$ExistingPackages = Get-CMPackage -Name $ScriptName -ErrorAction SilentlyContinue
if ($ExistingPackages) {
    foreach ($Package in $ExistingPackages) {
        Remove-CMPackage -Id $Package.PackageID -Force
    }
}

# Create the Package Source Directory if it does not exist
if (!(Test-Path -Path $PackageSourcePath)) {
    New-Item -ItemType Directory -Path $PackageSourcePath -Force
}

# Create the PowerShell script
$ScriptContent = @'
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Trace" -Name "Level" -Value 4 -PropertyType DWord -Force
'@

$ScriptPath = "$PackageSourcePath\$ScriptName.ps1"
Set-Content -Path $ScriptPath -Value $ScriptContent

# Create the SCCM Package
$Package = New-CMPackage `
    -Name $ScriptName `
    -Description $ScriptDescription `
    -Path $PackageSourcePath

# Create a Program for the Package
$Program = New-CMProgram `
    -PackageName $ScriptName `
    -StandardProgramName $ScriptName `
    -CommandLine "powershell.exe -ExecutionPolicy Bypass -File $ScriptPath" `
    -ProgramRunType "WhetherOrNotUserIsLoggedOn"

# Distribute the Package to the Distribution Point but do not deploy
Start-CMContentDistribution `
    -PackageName $ScriptName `
    -DistributionPointName "YourDistributionPointName"

Explanation

By creating an SCCM package using this script, you enable verbose logging for Windows Update across all targeted systems. This allows for more detailed logging of update processes, which can be crucial for diagnosing and troubleshooting any issues that arise during or after updates. Deploying this via SCCM ensures consistency and efficiency in enabling this setting across your organization.

Tags:

#WindowsUpdate #Logging #PowerShell #SCCM