Skip to content

Instantly share code, notes, and snippets.

@aaronpmiller
Created March 19, 2015 14:55

Revisions

  1. aaronpmiller created this gist Mar 19, 2015.
    61 changes: 61 additions & 0 deletions Update-WUMU_ExcludeKBVariables.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    <#
    .SYNOPSIS
    This script will create a series of SMS TSEnvironment variables with the prefix WUMU_ExcludeKB to tell ZTIWindowsUpdate to skip these updates.
    .DESCRIPTION
    This is an adaptation of a script provided by "The Deployment Guys" to exclude updates that cause multiple restarts as document in Microsoft KB2894518.
    What's (primarily) different in this script:
    1) Added logic to fallback to a list of known updates that cause this issue if we can't connect to the Microsoft KB.
    2) Added the ability to define a list of additional KBs to skip.
    3) Changed the Invoke-WebRequest to UseBasicParsing and the respective result parsing to workaround IE possibly not being ready to process requests (first run customizations).
    .LINK
    http://support.microsoft.com/kb/2894518
    .LINK
    http://blogs.technet.com/b/deploymentguys/archive/2015/03/11/excluding-known-multi-reboot-updates-during-a-zti-deployment.aspx
    #>


    PARAM (
    [string[]]$KnownMultipleRestartKBs=@('3036493','3039976','2984976','2981685','2966034','2965788','2920189','2871777','2871690','2862330','2771431','2821895','2545698','2529073'),
    [string[]]$AdditionalKBs
    )

    $tsEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
    $OldProgressPreference = $ProgressPreference
    $ProgressPreference="SilentlyContinue"
    $url = 'http://support.microsoft.com/kb/2894518'

    $webRequestSucceeded = $true
    try {
    Write-Host "Attempting to connect to '$url' to pull the latest list of KBs that require multiple restarts."
    $result = Invoke-WebRequest -Uri $url -UseBasicParsing
    } catch {
    $webRequestSucceeded = $false
    }

    [string[]]$allKBs = @()
    $allKBs += $AdditionalKBs
    if (($webRequestSucceeded -eq $true) -and ($result.Links.Count -gt 0) -and ($result.StatusCode -eq 200)) {
    Write-Host "The connection to '$url' succeeded, parsing the results for the current KBs..."
    $result.Links | Where-Object {($_.href -like "[h/]*kb/[0-9]*[0-9]") -and ($_.href -notlike "*/2894518")} | ForEach-Object {
    $allKBs += $_.href.split('/')[-1]
    }
    } else {
    Write-Host "The connection to '$url' failed, using a static list of known KBs"
    $allKBs += $KnownMultipleRestartKBs
    }

    $allKBs = $allKBs | Sort-Object -Unique | Where-Object {$_}

    Write-Host "The following variables will be created and the respective KBs will be skipped by ZTIWindowsUpdate..."
    $allKBs | ForEach-Object -Begin {$i=1} -Process {
    $tsEnv.Value("WUMU_ExcludeKB$i") = $_
    Write-Host "WUMU_ExcludeKB$i=$_"
    $i++
    }

    $ProgressPreference=$OldProgressPreference