ryan-jan / MSCatalog

PowerShell module for searching and downloading offline updates from https://www.catalog.update.microsoft.com
MIT License
58 stars 16 forks source link

Save-MSCatalog issue #30

Open codykonior opened 1 year ago

codykonior commented 1 year ago

It wasn't downloading anything for me. I updated Get-UpdateLinks.ps1 with:

$Regex = "(http[s]?\://dl\.delivery\.mp\.microsoft\.com\/[^\'\""]*)|(http[s]?\://catalog\.s\.download\.windowsupdate\.com\/[^\'\""]*)"

And now it works.

codykonior commented 1 year ago

What else I found useful adding to Save-MSCatalogUpdate.ps1:

    } elseif ($Language -and $Links.Matches.Where({$_.Value -match $Language})[0]) {
        [Switch] $All

...

        if (-not $All) {
            $SelectedId = Read-Host "Multiple files exist for this update. Enter the Id of the file to download or 'A' to download all files."
        } else {
            $SelectedId = "A"
        }
mgonzcast commented 1 year ago

It wasn't downloading anything for me. I updated Get-UpdateLinks.ps1 with:

$Regex = "(http[s]?\://dl\.delivery\.mp\.microsoft\.com\/[^\'\""]*)|(http[s]?\://catalog\.s\.download\.windowsupdate\.com\/[^\'\""]*)"

And now it works.

I have tried downloading from PSGallery and it doesn´t work. How can I fix it manually? I tried changing manually Get-UpdateLink.ps1 as you said and it doesn´t work either.

DW-42 commented 1 year ago

@mgonzcast , it seems that the release available via PowerShell Gallery is out of date compared to the code in Github.

It may be possible to get around this by downloading the Github repository ( Click on the "Code" button and select "Download ZIP" to download the repository as a zip file ) and extracted contents and overwrite the existing installation.

DW-42 commented 1 year ago

I have tried the above and got mixed results: Even after a reboot I was not able to Import the module by name.

PS C:\Users\UserName> Import-Module -Name MSCatalog
Import-Module : The specified module 'MSCatalog' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ Import-Module -Name MSCatalog
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (MSCatalog:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

...but I was able to Import the module using the full path to the psm1 file:

Import-Module "C:\Users\$ENV:UserName\Documents\WindowsPowerShell\Modules\MSCatalog\0.27.0\MSCatalog.psm1"

After this I found that I was able to use the Save-MSCatalogUpdate function successfully.

I feel like this is a bit of a messy solution, but until the PowerShell Gallery repository is updated I do not know of a better process.

mgonzcast commented 1 year ago

Many thanks! Now it seems to work!

Ok, I am trying to download the latests updates for Windows 10 1809 LTSC.

My search query i.e.: Latest updates in February is this one: "https://www.catalog.update.microsoft.com/Search.aspx?q=windows%2010%201809%20x64%20%25%2F02%2F2023"

For that, I use this powershell code:

$Updates=Get-MSCatalogUpdate -Search "windows 10 1809 x64 %/02/2023" Foreach ($item in $Updates) { Save-MSCatalogUpdate -Update $item -Destination "C:\Users\admin\Desktop\" } Id FileName


0 windows10.0-kb5022504-x64-ndp48_1febc9659953d8ffa0bd67ee7de672871fab3654.msu 1 windows10.0-kb5022511-x64_19dcbf71169b01c6337e5f6b98b937156d6a7a70.msu Multiple files exist for this update. Enter the Id of the file to download or 'A' to download all files.: A

It reports that I need to select manually all files, how can I automate that? Is there any All downloads flag?

Another issue, more general about Catalog downloads, but for Office 2016.

If I want to get the latest Office 2016 32 bits. This works:

https://www.catalog.update.microsoft.com/Search.aspx?q=Office%202016%2032%20bits

but I can´t query the dates:

https://www.catalog.update.microsoft.com/Search.aspx?q=Office%202016%2032%20bits%2002%2F2023

Many thanks for your help!

DW-42 commented 1 year ago

I feel like those sorts of questions a better answered on a platform like https://stackoverflow.com/ rather than here, but...

  1. Looking at codykonior's second post in this thread, the module could do with some tweaking when it comes to handling multiple files. :-(

  2. It looks like the search is only looking at the Title & Product fields, but not the Last Updated field. The PSObject that Get-MSCatalogUpdate returns includes the LastUpdated field, so you (at a guess) should be able to use Powershell's Where-Obect to filter the results. see: https://communary.net/2018/03/11/filtering-data-on-date-in-powershell/

mgonzcast commented 1 year ago

I feel like those sorts of questions a better answered on a platform like https://stackoverflow.com/ rather than here, but...

  1. Looking at codykonior's second post in this thread, the module could do with some tweaking when it comes to handling multiple files. :-(
  2. It looks like the search is only looking at the Title & Product fields, but not the Last Updated field. The PSObject that Get-MSCatalogUpdate returns includes the LastUpdated field, so you (at a guess) should be able to use Powershell's Where-Obect to filter the results. see: https://communary.net/2018/03/11/filtering-data-on-date-in-powershell/

Thanks @DW-42 ! Well, Stackoverflow refused my question about this because they don´t consider it as a programming question

In case someone is looking for a way to search Office Updates, as you suggested LastUpdated is the way to go

Get-MSCatalogUpdate -Search "Office 2016 32 bits" | Where-Object {$_.LastUpdated -ge "03/2023"}

So that should give me the 32 bits Office 2016 updates for March. Unfortunately I get another error related to the hash:

throw "The hash of the downloaded file does not match the

Even If I try the example showed in the main docs I get the hash error:

$Update = Get-MSCatalogUpdate -Search "Update for Microsoft Office 2013 (KB4011677) 32-Bit Edition" | Save-MSCatalogUpdate -Update $Update -Destination ".\" -Language "en-us" Anyway, for the Office updates I need to download the standalone EXE files, not the MSU files. How can I do that?

mgonzcast commented 1 year ago

@DW-42 @codykonior any ideas about the hash issue? In the end I solved it ignoring the error with:

Save-MSCatalogUpdate -Update $Updates -Destination $OutFolder -ErrorAction SilentlyContinue

Any idea of how can I download the standalone installer of an Office update?

mgonzcast commented 1 year ago

@DW-42 @codykonior any ideas about the hash issue? In the end I solved it ignoring the error with:

Save-MSCatalogUpdate -Update $Updates -Destination $OutFolder -ErrorAction SilentlyContinue

Any idea of how can I download the standalone installer of an Office update?

In the end I downloaded the cab file and use the command expand to extract the msp files. That way I can streamline the installation of the Office updates too

dmurh commented 9 months ago

new version installed from github .
if i do $Updates=Get-MSCatalogUpdate -Search "windows 11" and look into $Updates - i don`t see the GUID ---- and only 2 out of 25 files are downloaded
then i get The hash of the downloaded file does not match the expected value. At C:\Program Files\WindowsPowerShell\Modules\MSCatalog\MSCatalog\Private\Invoke-DownloadFile.ps1:30 char:13

and the script stops

also - -ErrorAction SilentlyContinue don`t solve

any ideas - i´m not good in powershell, but i will love to get all downloads and work with this

dmurh commented 9 months ago

ok - resolved the download problem by changing from Hash to signature - but the Switch "A" is not working

MikeZetPL commented 5 months ago

Hello all. I just wondering is nowadays still possible to use this cool code to download last OS & NET CUs for Windows 11 x64 23H2. Based on this tutorial: https://cherrypicking.dev/download-and-install-offline-windows-updates/ I created small script like that:

Install-Module -Name "MSCatalog"
Update-Module -Name "MSCatalog"
$DestinationDir = "D:\WinUpd"
$UpdCUStandardName      =   "Cumulative Update for Windows 11 Version 23H2 for x64-based Systems"

(Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | FL

$UpdCUStandardGuid      =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Guid").Guid
$UpdCUStandardTitle     =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Title").Title

Write-Host "UpdCUStandardGuid is: $UpdCUStandardGuid"
Write-Host "UpdCUStandardTitle is: $UpdCUStandardTitle"

Save-MSCatalogUpdate -Guid $UpdCUStandardGuid -Destination $DestinationDir

but its stops on: "Multiple files exist for this update. Enter the Id of the file to download or 'A' to download all files.:" xAP5m

From other hand builded on almost the same logic script for download CUs for Server 2019 x64 works fine: NvHm6

mgonzcast commented 5 months ago

Hello all. I just wondering is nowadays still possible to use this cool code to download last OS & NET CUs for Windows 11 x64 23H2. Based on this tutorial: https://cherrypicking.dev/download-and-install-offline-windows-updates/ I created small script like that:

Install-Module -Name "MSCatalog"
Update-Module -Name "MSCatalog"
$DestinationDir = "D:\WinUpd"
$UpdCUStandardName      =   "Cumulative Update for Windows 11 Version 23H2 for x64-based Systems"

(Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | FL

$UpdCUStandardGuid      =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Guid").Guid
$UpdCUStandardTitle     =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Title").Title

Write-Host "UpdCUStandardGuid is: $UpdCUStandardGuid"
Write-Host "UpdCUStandardTitle is: $UpdCUStandardTitle"

Save-MSCatalogUpdate -Guid $UpdCUStandardGuid -Destination $DestinationDir

but its stops on: "Multiple files exist for this update. Enter the Id of the file to download or 'A' to download all files.:" xAP5m

From other hand builded on almost the same logic script for download CUs for Server 2019 x64 works fine: NvHm6

Have you tried @MikeZetPL the AcceptMultiFileUpdates flag when using Save-MSCatalogUpdate ?

MikeZetPL commented 5 months ago

Have you tried @MikeZetPL the AcceptMultiFileUpdates flag when using Save-MSCatalogUpdate ?

Yes, and also discovered then, that command:

Install-Module -Name "MSCatalog" will by default install this module in v. 0.27.0

Switch what you mentioned is from v. 0.28.0

Anyway I manually downloaded this last ver from this repository - link: https://github.com/ryan-jan/MSCatalog/archive/refs/heads/master.zip

and replaced Module in default dir.

After that I tested it one more time: with bellow command:


$DestinationDir = "D:\"
$UpdCUStandardName      =   "Cumulative Update for Windows 11 Version 23H2 for x64-based Systems"
(Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | FL

$UpdCUStandardGuid      =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Guid").Guid
$UpdCUStandardTitle     =   ((Get-MSCatalogUpdate -Search $UpdCUStandardName) | Where { $_.Title -match $UpdCUStandardName } | Select -First 1 | Select-Object -Property "Title").Title

Write-Host "UpdCUStandardGuid is: $UpdCUStandardGuid"
Write-Host "UpdCUStandardTitle is: $UpdCUStandardTitle"

Save-MSCatalogUpdate -AcceptMultiFileUpdates -Guid $UpdCUStandardGuid -Destination $DestinationDir 

Unfortunatelly with no luck also this time:

2024-02-14_17-13-15

Function can find Update what I'm looking for, I can take it GUID, Name, etc, but second Function (Save-MSCatalogUpdate) can't download this file directly. BTW Its only one update file to download. When you try to save it, then for a while it blinks and write like it can be saw on upper print screen empty table with ID and FileName.

What can I do at this point its just generate and start web address to direct MS Catalog page with that update, when I have to press manually "Download" button:

Start ("https://www.catalog.update.microsoft.com/Search.aspx?q=" + $UpdCUStandardGuid)

But its not fully automated, what I'm trying to archive.

mgonzcast commented 5 months ago

@MikeZetPL As far as I know you have to use a loop to get every file.

I paste my code for Windows 10 updates in case it helps you:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$cwd = (Get-Location).Path
$MSCatalogModule = "$($cwd)\powershell\MSCatalog\MSCatalog.psm1"

Import-Module $MSCatalogModule

$Month=(Get-Date -Format MM)

$Year=(Get-Date).Year|Out-String -Stream

$Date=($Month).ToString('00') + "/" + $Year

$OutFolder = "$($cwd)\updates\Microsoft"

$Updates=Get-MSCatalogUpdate -AllPages -Search "Security windows 10 1809 x64" | Where-Object {$_.LastUpdated -ge $Date}

if ($Updates -eq $null){ Write-Host "`r`nNo updates from $Date"} else {
    Foreach ($item in $Updates) { Save-MSCatalogUpdate -AcceptMultiFileUpdates -Update $item -Destination $OutFolder }
}
MikeZetPL commented 5 months ago

@mgonzcast your code work for me too (download for Win10 CUs is successful), until in search field I change from: "Security windows 10 1809 x64" to: "Security windows 11 23H2 x64".

Then I have only blank table with ID and FileName

image

From other hand this search in Microsoft catalog give right result: image

mgonzcast commented 5 months ago

@MikeZetPL I have tried myself and you are right, It doesn´t seem to work

@ryan-jan Maybe we have come across a bug? It doesn´t seem to download any file when it comes to Windows 11 KBs

JozeMarkic commented 4 months ago

@MikeZetPL @codykonior @mgonzcast @dmurh Based on my testing and current solution to the downloading problem, downloading newer files (Windows 11) doesn't work because they can't be found on existing hosting servers. You can spot this behavior as empty table with no ID and FileName.

The problem is RegEx syntax in Get-UpdateLinks function - you can find this function in module's Private folder in it's own file (Get-UpdateLinks.ps1). If you update the RegEx, downloading problem should be resolved (at least until next time when MS introduces new hosting servers). My current working RegEx: $Regex = "(http[s]?\:\/\/(?:[a-z,.]*dl\.delivery\.mp\.microsoft\.com|(?:catalog\.s\.)?download\.windowsupdate\.com)\/[^\'\""]*)"

MikeZetPL commented 4 months ago

Wow. Its working now. Thank you very much for solve it @JozeMarkic :)

It was just a matter of small change in Get-UpdateLinks.ps1 in var: $Regex:

2024-03-11_13-09-17

[I specially leave and disabled old $Regex to compare it. So its seems solve it was just a matter extra adding in that var: '[a-z,.]*']