forked from potatoqualitee/kbupdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildfromwsus.ps1
94 lines (73 loc) · 3.56 KB
/
buildfromwsus.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function buildfromwsus {
$temp = Get-PSFPath -Name Temp
$basedir = Join-PSFPath -Path $temp wsus
if (-not (Test-Path -Path $basedir)) {
$null = mkdir $basedir
}
#Set-Location $basedir
# Download WSUS database
if (-not (Test-Path -Path "$basedir\wsusscn2.cab")) {
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri http://download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab -OutFile $basedir\wsusscn2.cab
}
$cab = New-Object Microsoft.Deployment.Compression.Cab.Cabinfo $basedir\wsusscn2.cab
$null = $cab.UnpackFile("package.cab", "$basedir\package.cab")
$xmlfile = "$basedir\package.xml"
$cab = New-Object Microsoft.Deployment.Compression.Cab.Cabinfo $basedir\package.cab
$null = $cab.UnpackFile("package.xml", $xmlfile)
$xml = [xml](Get-Content -Path $xmlfile)
$newer = $xml.OfflineSyncPackage.Updates.Update #| Where-Object CreationDate -gt "2022-02-09 23:19:20"
$ds = New-Object System.Data.DataSet
$ds.ReadXml($xmlfile)
($ds.Tables["FileLocation"].Select("Id = '$fileid'")).Url
$newer = Import-Csv C:\temp\kb\products.csv
$newer | Where-Object UpdateId | Invoke-Parallel -ImportVariables -ImportFunctions -RunspaceTimeout 180 -Quiet -ScriptBlock {
$guid = $PSItem.UpdateId
if ((Get-KbUpdate -Pattern $guid -OutVariable output -Source Web)) {
$output | Export-CliXml C:\temp\kb\newoutput\$guid.xml
} else {
write-warning $guid
}
}
#($xml.OfflineSyncPackage.FileLocations | Select-XML -Xpath "//*[@Id='$fileid']").Node.Url
$temp = Get-PSFPath -Name Temp
$basedir = Join-PSFPath -Path $temp wsus
if (-not (Test-Path -Path $basedir)) {
$null = mkdir $basedir
}
#Set-Location $basedir
# Download WSUS database
if (-not (Test-Path -Path "$basedir\wsusscn2.cab")) {
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri http://download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab -OutFile $basedir\wsusscn2.cab
}
$db = "C:\github\kbupdate-library\library\kb.sqlite"
$cab = New-Object Microsoft.Deployment.Compression.Cab.Cabinfo $basedir\wsusscn2.cab
$null = $cab.UnpackFile("package.cab", "$basedir\package.cab")
$xmlfile = "$basedir\package.xml"
$cab = New-Object Microsoft.Deployment.Compression.Cab.Cabinfo $basedir\package.cab
$null = $cab.UnpackFile("package.xml", $xmlfile)
$xml = [xml](Get-Content -Path $xmlfile)
$newer = $xml.OfflineSyncPackage.Updates.Updates
$ds = New-Object System.Data.DataSet
$ds.ReadXml($xmlfile)
$updates = $xml.OfflineSyncPackage.Updates
foreach ($update in $updates.Update) {
if ($update.PayloadFiles.File) {
Invoke-SqliteQuery -DataSource $db -Query "delete from Link where UpdateId = '$($update.UpdateId)'"
}
foreach ($file in $update.PayloadFiles.File) {
$fileid = $file.id
$url = ($ds.Tables["FileLocation"].Select("Id = '$fileid'")).Url
$url = $url.Replace("http://download.windowsupdate.com", "https://catalog.s.download.windowsupdate.com")
$url = $url.Replace("http://www.download.windowsupdate.com", "https://catalog.s.download.windowsupdate.com")
if ($url) {
Invoke-SQLiteBulkCopy -DataTable (
[pscustomobject]@{
UpdateId = $update.UpdateId
Link = $url
} | ConvertTo-DbaDataTable) -DataSource $db -Table Link -Confirm:$false
}
}
}
}