Public/Save-MSCatalogUpdate.ps1
function Save-MSCatalogUpdate { <# .SYNOPSIS Download an update file from catalog.update.micrsosoft.com. .PARAMETER Guid Specify the Guid for the update to be downloaded. The Guid is retrieved using the Get-MSCatalogUpdate function. .PARAMETER Destination Specify the destination directory to download the update to. .PARAMETER Language Some updates are available in multiple languages. By default this function will list all available files for a specific update and prompt you to select the one to download. If you wish to remove this prompt you can specify a language-country code combination e.g. "en-us". .EXAMPLE $Guid = Get-MSCatalogUpdate -Search "KB4011677" -Architecture "32-Bit" | Select-Object -ExpandProperty Guid Save-MSCatalogUpdate -Guid $Guid -Destination C:\Windows\Temp\ -Language "en-us" .EXAMPLE Get-MSCatalogUpdate -Search "KB4011677" -Architecture "32-Bit" | Save-MSCatalogUpdate -Destination C:\Windows\Temp\ -Language "en-us" #> param ( [Parameter( Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true )] [String] $Guid, [Parameter( Mandatory = $true, Position = 1 )] [String] $Destination, [Parameter( Mandatory = $false, Position = 2 )] [String] $Language ) $Post = @{size = 0; updateID = $Guid; uidInfo = $Guid} | ConvertTo-Json -Compress $Body = @{updateIDs = "[$Post]"} $Params = @{ Uri = "https://www.catalog.update.microsoft.com/DownloadDialog.aspx" Method = "Post" Body = $Body ContentType = "application/x-www-form-urlencoded" UseBasicParsing = $true } $DownloadDialog = Invoke-WebRequest @Params $Links = $DownloadDialog.Content.Replace("www.download.windowsupdate", "download.windowsupdate") $Links = $Links | Select-String -AllMatches -Pattern "(http[s]?\://download\.windowsupdate\.com\/[^\'\""]*)" $Links.Matches.Count if ($Links.Matches.Count -eq 1) { $Link = $Links.Matches[0] $Params = @{ Uri = $Link.Value OutFile = (Join-Path -Path $Destination -ChildPath $Link.Value.Split('/')[-1]) } Invoke-WebRequest @Params } elseif ($Language) { $Link = $Links.Matches.Where({$_.Value -match $Language})[0] $Params = @{ Uri = $Link.Value OutFile = (Join-Path -Path $Destination -ChildPath $Link.Value.Split('/')[-1]) } Invoke-WebRequest @Params } else { Write-Host "Id FileName`r" Write-Host "-- --------" foreach ($Link in $Links.Matches) { $Id = $Links.Matches.IndexOf($Link) $FileName = $Link.Value.Split('/')[-1] if ($Id -lt 10) { Write-Host " $Id $FileName`r" } else { Write-Host "$Id $FileName`r" } } $Selected = Read-Host "Enter the Id of the file to download" $Params = @{ Uri = $Links.Matches[$Selected].Value OutFile = (Join-Path -Path $Destination -ChildPath $FileName) } Invoke-WebRequest @Params } } |