-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGet-KnownIssuesWindowsUpdates.ps1
1477 lines (1124 loc) · 55 KB
/
Get-KnownIssuesWindowsUpdates.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -Version 3.0
Function Get-IssuesWindowsUpdateReport {
<#
.SYNOPSIS
This script is used to report on Windows Updates that are known to cause issues. It sends an email to the recipient you specify with an HTML file attached.
.DESCRIPTION
Obtain information on updates that are known to have issues when applied. The HTML file that is created offers more functionality than the email becuase email does not execute javascript.
.PARAMETER HtmlFile
Define the location to save the HTML file containing the collected information
.PARAMETER ToEmail
Define the email address(es) to send the report information too
.PARAMETER FromEmail
Define the email address to send an email from
.PARAMETER SmtpServer
Define the SMTP server to send an email from
.PARAMETER EmailPort
Define the SMTP port to send the email from
.PARAMETER EmailCredential
Defeine your credentials used to send an email
.PARAMETER UseSSL
Define whether to use TLS when sending an email
.PARAMETER LogoFilePath
Define the path to a company image to include in the email and report. Roughly 800px by 200px usually looks nice. Max width is 975px
.PARAMETER HtmlBodyBackgroundColor
Define the main HTML body background color
.PARAMETER HtmlBodyTextColor
Define the text color used in paragraphs
.PARAMETER H1BackgroundColor
Define the background color for h1 HTML values
.PARAMETER H1BackgroundFadeColor
Define the background fade color for header 1 items
.PARAMETER H1TextColor
Define the text color used in H1 elements
.PARAMETER H1BorderColor
Define the color used in H1 borders
.PARAMETER H2TextColor
Define the background color for h1 HTML values
.PARAMETER H3BackgroundColor
Define the background color for h1 HTML values
.PARAMETER H3BorderColor
Define the border color for h1 HTML values
.PARAMETER H3TextColor
Define the text color of h3 elements
.PARAMETER TableHeaderBackgroundColor
Define the background color of the tables headers
.PARAMETER TableHeaderFadeColor
Define the fade color of the table header
.PARAMETER TableHeaderTextColor
Define the text color of the tables headers
.PARAMETER TableBodyBackgroundColor
Define the background color of the tables data
.PARAMETER TableTextColor
Define the text color in the tables data
.PARAMETER TableBorderColor
Define the border color in the table
.PARAMETER ButtonHoverBackgroundColor
Define the background color of the buttons after mouse hover
.PARAMETER ButtonHoverTextColor
Define the color of the text of buttons after mouse hover
.PARAMETER SearchButtonBackgroundColor
Define the background color for the buttons
.EXAMPLE
PS> .\Get-KnownIssuesWindowsUpdates.ps1 -ToEmail "rosborne@osbornepro.com" -FromEmail "rosborne@osbornepro.com" -SmtpServer mail.smtp2go.com -UseSSL -EmailPort 587 -EmailCredential $LiveCred -LogoFilePath "$env:ONEDRIVE\Pictures\Logos\logo-banner.png" -H1BackgroundColor '#121F48' -H1TextColor '#FFFFFF' -H1BorderColor "Black" -H2TextColor '#AC1F2D' -H3BackgroundColor '#121F48' -H3FadeBackgroundColor '#AC1F2D' -H3BorderColor 'Black' -H3TextColor 'white' -TableHeaderBackgroundColor '#121F48' -TableHeaderFadeColor '#AC1F2D' -TableHeaderTextColor 'white' -TableBorderColor 'Black'
# This example generates a report using national colors of the United States to make a professional looking report that is delivered via email
.LINK
https://github.com/tobor88
https://github.com/osbornepro
https://www.powershellgallery.com/profiles/tobor
https://osbornepro.com
https://writeups.osbornepro.com
https://encrypit.osbornepro.com
https://btpssecpack.osbornepro.com
https://www.powershellgallery.com/profiles/tobor
https://www.hackthebox.eu/profile/52286
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: rosborne@osbornepro.com
RSS FEEDS APPEAR TO NOT HAVE ANY USEFUL INFORMATION. I LEFT THIS HERE IN CASE IT IS DISCOVERED OTHERWISE
$MicrosoftUpdateRssFeedUri = "https://support.microsoft.com/en-us/feed/rss/7abe4ae9-060b-5746-376f-232cf5c9946d"
$WindowsUpdateRssFeedUri = "https://support.microsoft.com/en-us/feed/rss/8006984f-11e7-355b-5a81-fb46edef60fa"
$MicrosoftUpdatesRssResults = Invoke-RestMethod -Method GET -Uri $MicrosoftUpdateRssFeedUri -UserAgent $UserAgent -ContentType 'application/xml' -Verbose:$False
$WindowsUpdatesRssResults = Invoke-RestMethod -Method GET -Uri $WindowsUpdateRssFeedUri -UserAgent $UserAgent -ContentType 'application/xml' -Verbose:$False
#>
[CmdletBinding()]
param(
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$HtmlFile = "$env:TEMP\Windows-Patch-Report.html",
[Parameter(
Mandatory=$True,
HelpMessage="Enter the email address(es) to send the information too "
)] # End Parameter
[String[]]$ToEmail,
[Parameter(
Mandatory=$True,
HelpMessage="Enter the email address(es) to send the information from "
)] # End Parameter
[String]$FromEmail,
[Parameter(
Mandatory=$True,
HelpMessage="Enter the SMTP server to send the information from "
)] # End Parameter
[String]$SmtpServer,
[Parameter(
Mandatory=$False
)] # End Parameter
[ValidateRange(1, 65535)]
[Int]$EmailPort = 25,
[Parameter(
Mandatory=$False
)] # End Parameter
[Switch]$UseSSL,
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
[Parameter(
Mandatory=$False
)] # End Parameter
$EmailCredential = [System.Management.Automation.PSCredential]::Empty
[Parameter(
Mandatory=$False
)] # End Parameter
[ValidateScript({$_.Extension -like ".png" -or $_.Extension -like ".jpg" -or $_.Extension -like ".jpeg"})]
[System.IO.FileInfo]$LogoFilePath,
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$HtmlBodyBackgroundColor='#292929',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$HtmlBodyTextColor = '#ECF9EC',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H1BackgroundColor = '#259943',
[Parameter(
Mandatpry=$False
)] # End Parameter
[String]$H1BackgroundFadeColor = '#000000',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H1TextColor = '#ECF9EC',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H1BorderColor = '#666666',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H2TextColor = '#FF4D04',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H3BackgroundColor = '#259943',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H3BorderColor = '#666666',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H3FadeBackgroundColor = '#000000',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$H3TextColor = '#ECF9EC',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableTextColor = '#1690D0',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableHeaderBackgroundColor = '#259943',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableHeaderFadeColor = '#000000',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableHeaderTextColor = '#ECF9EC',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableBorderColor = '#000000',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$TableBodyBackgroundColor = '#FFE3CC',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$ButtonHoverBackgroundColor = '#FF7D15',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$ButtonHoverTextColor = '#FFFFFF',
[Parameter(
Mandatory=$False
)] # End Parameter
[String]$SearchButtonBackgroundColor = '#1690D0'
) # End param
Write-Debug -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Loading custom cmdlets into session"
Function Get-DayOfTheWeeksNumber {
[CmdletBinding()]
param(
[Parameter(
Position=0,
Mandatory=$True,
ValueFromPipeline=$False,
HelpMessage="Define the day of the week you want: `nEXAMPLE: Tuesday")] # End Parameter
[ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')]
[String]$DayOfWeek,
[Parameter(
Position=1,
Mandatory=$True,
ValueFromPipeline=$False,
HelpMessage="Identify which week of the month you want: `nEXAMPLE: 2")] # End Parameter
[ValidateRange(1,6)]
[Int32]$WhichWeek,
[Parameter(
Position=2,
Mandatory=$False,
ValueFromPipeline=$False,
HelpMessage="Identify which week of the month you want: `nEXAMPLE: 2")] # End Parameter
[ValidateSet('January','February','March','April','May','June','July','August','September','October','November','December')]
[String]$Month = $((Get-Culture).DateTimeFormat.GetMonthName((Get-Date).Month)),
[Parameter(
Position=3,
Mandatory=$False,
ValueFromPipeline=$False,
HelpMessage="Identify which week of the month you want: `nEXAMPLE: 2")] # End Parameter
[ValidateScript({$_ -match '(\d\d\d\d)'})]
[Int32]$Year = (Get-Date).Year
) # End param
$Today = Get-Date -Date "$Month $Year"
$Subtract = $Today.Day - 1
[DateTime]$MonthStart = $Today.AddDays(-$Subtract)
While ($MonthStart.DayOfWeek -ne $DayOfWeek) {
$MonthStart = $MonthStart.AddDays(1)
} # End While
Return $MonthStart.AddDays(7*($WhichWeek - 1))
} # End Get-DayOfTheWeeksNumber
Function Get-KBDownloadLink {
<#
.SYNOPSIS
This cmdlet is used to retrieve from the Microsoft Update Catalog, a download link for the Article ID KB number you specify
.DESCRIPTION
Retrieves the KB Download link from the Microsoft Update Catalog
.PARAMETER ArticleID
Defines the KB identification number you want to retrieve a download link for
.PARAMETER OperatingSystem
Define the Operating System you want a link for
.PARAMETER Architecture
Define the architecture of the system you are going to install the update on. Default value is x64
.PARAMETER VersionInfo
Define the version of Windows 10 or 11 being used
.EXAMPLE
Get-KBDownloadLink -ArticleId KB5014692
# This obtains the download link for KB5014692 for the OS version and arhcitecture of the machine this command is executed on
.EXAMPLE
Get-KBDownloadLink -ArticleId KB5014692 -Architecture "x64" -OperatingSystem 'Windows Server 2019'
# This obtains the download link for KB5014692 for a 64-bit architecture Windows Server 2019 machine
.EXAMPLE
Get-KBDownloadLink -ArticleId KB5014692 -Architecture "x64" -OperatingSystem 'Windows 10' -VersionInfo '21H1'
# This obtains the download link for KB5014692 for a 64-bit architecture Windows 10 Enterprise version 21H1 machine
.INPUTS
None
.OUTPUTS
System.String[]
.NOTES
Author: Robrt H. Osborne
Alias: tobor
Contact: rosborne@osbornepro.com
.LINK
https://github.com/tobor88
https://github.com/osbornepro
https://www.powershellgallery.com/profiles/tobor
https://osbornepro.com
https://writeups.osbornepro.com
https://encrypit.osbornepro.com
https://btpssecpack.osbornepro.com
https://www.powershellgallery.com/profiles/tobor
https://www.hackthebox.eu/profile/52286
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
#>
[OutputType([System.String])]
[CmdletBinding(DefaultParameterSetName="Server")]
param(
[Parameter(
Position=0,
Mandatory=$True,
ValueFromPipeline=$False,
HelpMessage="Enter the KB number `nEXAMPLE: KB5014692 `nEXAMPLE: 5014692 "
)] # End Parameter
[Alias("Id","Article","KB")]
[String]$ArticleId,
[Parameter(
Position=1,
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[ValidateSet("Windows Server 2008", "Windows Server 2008 R2", "Windows Server 2012", "Windows Server 2012 R2", "Windows Server 2016", "Windows Server 2019", "Windows Server 2022", "Windows 10", "Windows 11","SQL Server 2014","SQL Server 2016","SQL Server 2017","SQL Server 2019")]
[String]$OperatingSystem = "$((Get-CimInstance -ClassName Win32_OperatingSystem -Verbose:$False).Caption.Replace('Microsoft ','').Replace(' Pro','').Replace(' Standard ','').Replace(' Datacenter ',''))",
[Parameter(
Position=2,
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[ValidateSet("x64", "x86", "ARM")]
[String]$Architecture,
[Parameter(
ParameterSetName="Windows10",
Position=3,
Mandatory=$False,
ValueFromPipeline=$False
)] # End Parameter
[Alias('Windows10Version','Windows11Version')]
[String]$VersionInfo
) # End param
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Tls12,Tls13'
$DownloadLink = @()
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox
$UpdateIdResponse = Invoke-WebRequest -Uri "https://www.catalog.update.microsoft.com/Search.aspx?q=$ArticleId" -Method GET -UserAgent $UserAgent -ContentType 'text/html; charset=utf-8' -UseBasicParsing -Verbose:$False
$DownloadOptions = ($UpdateIdResponse.Links | Where-Object -Property ID -like "*_link")
If (!($PSBoundParameters.ContainsKey('Architecture') -and $OperatingSystem -notlike "*SQL*")) {
$Architecture = "x$((Get-CimInstance -ClassName Win32_OperatingSystem -Verbose:$False).OSArchitecture.Replace('-bit',''))"
} # End If
If ($PSCmdlet.ParameterSetName -eq "Windows10" -and $OperatingSystem -notlike "*SQL*") {
If (!($PSBoundParameters.ContainsKey('VersionInfo') -and $OperatingSystem -notlike "*SQL*")) {
$VersionInfo = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name DisplayVersion).DisplayVersion
} # End If
Write-verbose -Message "$OperatingSystem link being discovered"
If ($OperatingSystem -like "Windows Server 2022") {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { ($_.OuterHTML -like "*$($OperatingSystem)*" -or $_.OuterHTML -like "*Microsoft server operating system, version *") }
} Else {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { $_.OuterHTML -like "*$($OperatingSystem)*" -and $_.OuterHTML -notlike "*Dynamic*" }
} # End If Else
If ($PSBoundParameters.Contains('Architecture')) {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { $_.OuterHTML -like "*$($Architecture)*" }
} # End If
} Else {
Write-verbose -Message "$OperatingSystem link being discovered"
If ($OperatingSystem -like "Windows Server 2022") {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { ($_.OuterHTML -like "*$($OperatingSystem)*" -or $_.OuterHTML -like "*Microsoft server operating system, version *") }
} Else {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { $_.OuterHTML -like "*$($OperatingSystem)*" -and $_.OuterHTML -notlike "*Dynamic*" }
} # End If Else
If ($PSBoundParameters.ContainsKey('Architecture') -and $OperatingSystem -notlike "*SQL*") {
$DownloadOptions = $DownloadOptions | Where-Object -FilterScript { $_.OuterHTML -like "*$($Architecture)*" }
} # End If
} # End If Else
If ($Null -eq $DownloadOptions) {
Throw "[x] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') No results were returned using the specified options $OperatingSystem and $Architecture"
} # End If
ForEach ($DownloadOption in $DownloadOptions) {
$Guid = $DownloadOption.id.Replace("_link","")
Write-Verbose -Message "Downloading information for $($ArticleID) $($Guid)"
$Body = @{ UpdateIDs = "[$(@{ Size = 0; UpdateID = $Guid; UidInfo = $Guid } | ConvertTo-Json -Compress)]" }
$LinksResponse = (Invoke-WebRequest -Uri 'https://catalog.update.microsoft.com/DownloadDialog.aspx' -Method POST -Body $Body -UseBasicParsing -SessionVariable WebSession -Verbose:$False).Content
$DownloadLink += ($LinksResponse.Split("$([Environment]::NewLine)") | Select-String -Pattern 'downloadInformation' | Select-String -Pattern 'url' | Out-String).Trim()
If ($PSBoundParameters.ContainsKey('Architecture') -and $OperatingSystem -like "*SQL*") {
$DownloadLink = ($DownloadLink | ForEach-Object { $_.Split("$([System.Environment]::NewLine)") } | Where-Object -FilterScript { $_ -like "*$Architecture*" }).Trim().Split("'")[-2]
} ElseIf ($OperatingSystem -like "*SQL*") {
$DownloadLink = ($DownloadLink | ForEach-Object { $_.Split("'") } | Where-Object -FilterScript { $_ -like "https://*" }).Split("$([System.Environment]::NewLine)")
} Else {
$DownloadLink = ($LinksResponse.Split("$([Environment]::NewLine)") | Select-String -Pattern 'downloadInformation' | Select-String -Pattern 'url' | Out-String).Trim().Split("'")[-2]
} # End If Else
} # End ForEach
Return $DownloadLink
} # End Function Get-KBDownloadLink
Function Get-WindowsUpdateIssue {
<#
.SYNOPSIS
This script is used to collect Reddit posts on Windows Updates that caused issues
.DESCRIPTION
Query Reddit for posts related to Windows Updates causing issues
.PARAMETER ArticleID
Define the KB number(s) to return information on
.EXAMPLE
PS> Get-WindowsUpdateIssue
# This example returns release note information on all KBs for the latest patching month
.EXAMPLE
PS> Get-WindowsUpdateIssue
# This example returns release note information on the defined KB for the latest patch month
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: rosborne@osbornepro.com
.LINK
https://osbornepro.com/
.INPUTS
None
.OUTPUTS
System.Object[]
#>
[OutputType([System.Object[]])]
[CmdletBinding()]
param(
[Parameter(
Mandatory=$False
)] # End Parameter
[String[]]$ArticleID
) # End param
Write-Debug -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Ensuring the use of TLSv1.2"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox
If ($ArticleID) {
$ArticleIDs = $ArticleID
} Else {
Write-Verbose -Message "[v] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Getting $(Get-Date -UFormat '%B %Y') Windows Updates"
$MsrcUri = "https://api.msrc.microsoft.com/cvrf/v2.0/updates('$(Get-Date -UFormat %Y-%b)')"
Try {
$MicrosoftSecUpdateLink = (Invoke-RestMethod -UseBasicParsing -Method GET -ContentType 'application/json' -UserAgent $UserAgent -Uri $MsrcUri -Verbose:$False).Value.CvrfUrl
} Catch {
$MicrosoftSecUpdateLink = (Invoke-RestMethod -UseBasicParsing -Method GET -ContentType 'application/json' -UserAgent $UserAgent -Uri "https://api.msrc.microsoft.com/cvrf/v2.0/updates('$(Get-Date -Date (Get-Date).AddMonths(-1) -UFormat %Y-%b)')" -Verbose:$False).Value.CvrfUrl
} # End Try Catch
Write-Verbose -Message "[v] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Getting $(Get-Date -UFormat '%B %Y') Windows Update Artilce ID values"
$MicrosoftSecInfo = Invoke-RestMethod -UseBasicParsing -Method GET -ContentType 'application/json' -UserAgent $UserAgent -Uri $MicrosoftSecUpdateLink -Verbose:$False
$ArticleIDs = $MicrosoftSecInfo.Vulnerability.Remediations | ForEach-Object {
If ($_.Url -and $_.Url -like "*/site/Search.aspx?q=KB*") {
$($_.Url.Split('=')[-1])
} # End If
} | Select-Object -Unique
} # End If Else
$PatchTuesday = Get-DayOfTheWeeksNumber -DayOfWeek Tuesday -WhichWeek 2 -Verbose:$False
$Output = ForEach ($KB in $ArticleIDs) {
$ReleaseNotesUri = "https://support.microsoft.com/help/$($KB.Replace('KB', ''))"
$KBReleaseNotes = Invoke-WebRequest -UseBasicParsing -Uri $ReleaseNotesUri -Method GET -UserAgent $UserAgent -ContentType 'text/html; charset=utf-8' -Verbose:$False
$NoIssuesKnown = $KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "(We|Microsoft) (is|are) (not currently|currently not) aware of any issues (in|with) this update." }
If (!($NoIssuesKnown)) {
$NoIssuesKnown = $KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "No additional issues were documented for this release" }
} # End If
$OSBuild = ($KBReleaseNotes.Links.outerHTML.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "I think you" } | Out-String | Select-String -Pattern "(\d+)\.(\d+)" -Context 0).Matches.Value
If ((!($OSBuild)) -or $OSBuild -like "4.*" -or $OSBuild -like "3.*" -or $OSBuild -like "2.*") {
Try {
$OSes = ($KBReleaseNotes.Links.outerHTML.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "Windows Server (\d+) (.*)" -Context 0}).Matches.Value.Split('<')[0].Split('(')[0].Replace(' update history', '')
} Catch {
# Gets .NET Framework Operating System Applicability
Try {
$OSes = ((($KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "$(Get-Date -Date $PatchTuesday -UFormat '%B %e, %Y') (.*) Windows (.*)" -Context 0}).Matches.Value.Split('<')[0] | Out-String | Select-String -Pattern "Windows (.*)" -Context 0).Matches.Value -Split "includes" | Select-Object -First 1).Trim().Replace(' update history', '')
} Catch {
Try {
# Windows Server Grep
$OSes = ($KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "Windows Server (\d+) (.*)" -Context 0}).Matches.Value.Split('<')[0].Replace(' update history', '').Replace(' - Microsoft Support', '')
} Catch {
# Windows Desktop Grep
Try {
$OSes = ($KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "Windows (\d+) Version (.*)" -Context 0}).Matches.Value.Split('<')[0].Replace(' update history', '').Replace(' - Microsoft Support', '')
} Catch {
$OSes = ($KBReleaseNotes.RawContent.Split("`n") | ForEach-Object { $_ | Select-String -Pattern "Windows (\d+), Version (.*)" -Context 0}).Matches.Value.Split('<')[0].Replace(' update history', '').Replace(' - Microsoft Support', '').Replace(',', '').Replace('version', 'Version')
} # End Try Catch
} # End Try Catch
} # End Try Catch
} # End Try Catch
If ($OSes -like "* and *") {
$OSes = $OSes -Split "and "
} # End If
} # End If
If (!($OSes)) {
Switch -Wildcard ($OSBuild) {
"*20348.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2022" -Force -WhatIf:$False }
"17763.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2019, Windows 10 1809" -Force -WhatIf:$False }
"*14393.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2016, Windows 10 1607" -Force -WhatIf:$False }
"*6.3.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2012 R2" -Force -WhatIf:$False }
"*6.2.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2012" -Force -WhatIf:$False }
"*6.1.*" { Set-Variable -Name OperatingSystem,OSVersion -Value "Windows Server 2008 R2" -Force -WhatIf:$False }
"*22621.*" { $OSVersion = "Windows 11 22H2"; $OperatingSystem = "Windows 11" }
"*22000.*" { $OSVersion = "Windows 11 21H2"; $OperatingSystem = "Windows 11" }
"*19045.*" { $OSVersion = "Windows 10 22H2"; $OperatingSystem = "Windows 10" }
"*19044.*" { $OSVersion = "Windows 10 21H2"; $OperatingSystem = "Windows 10" }
"*10240.*" { $OSVersion = "Windows 10 1507"; $OperatingSystem = "Windows 10" }
"4.*" { $OSVersion = ".NET Framework $OSBuild" }
"3.*" { $OSVersion = ".NET Framework $OSBuild" }
"2.*" { $OSVersion = ".NET Framework $OSBuild" }
Default { $OSVersion = $OSBuild
} # End Switch
If ($OSVersion -notlike ".NET Framework*") {
$OperatingSystem = $OperatingSystem.Split(',')[0].Replace(' SP1', '').Replace(' SP2', '').Replace("Windows Server 2008 R2 and Windows Server 2008", "Windows Server 2008 R2").Replace('Windows 11 Version 22H2' ,'Windows 11').Replace('Windows 10 Version 21H2 and Windows 10 Version 22H2', 'Windows 10').Trim()
$DownloadLink = Get-KBDownloadLink -ArticleId $KB -OperatingSystem $OperatingSystem -Architecture "x64" -Verbose:$False -ErrorAction SilentlyContinue
} # End If
If (!($NoIssuesKnown)) {
$Match = ($KBReleaseNotes.RawContent | Select-String -Pattern 'Known issues in this update</h(\d)>(.|\n)*?<tbody>(.|\n)*?<\/tbody>' -AllMatches).Matches.Value
$PTags = ($Match | Select-String -Pattern '<p>(.|\n)*?<\/p>' -AllMatches).Matches.Value | Where-Object -FilterScript { $_ -notlike '<p></p>' -and $_ -notmatch ">Symptom<" -and $_ -notmatch ">Workaround<" -and $_ -notmatch ">Registry key function</b>" -and $_ -notmatch ">Next step<" -and $_ -notlike '<p></p>' -and $_ -notlike "*>Symptom<*" -and $_ -notlike "*>Workaround<*" -and $_ -notlike "*>Next step<*" }
$Issue = $PTags[0].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ') + $(If ($PTags[1] -like "*>Note*") { "<br>$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))" } )
$Workaround = ($PTags | Where-Object -FilterScript { $_ -notlike $PTags[0]}).Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ')
If ($PTags[1] -like "*>Note*") {
$Workaround = $Workaround.Replace("$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))", "")
} # End If
} # End If
New-Object -TypeName PSCustomObject -Property @{
KB=$KB;
OperatingSystem=$OSVersion;
Reference=$ReleaseNotesUri;
DownloadLink=$(If ($DownloadLink) { $DownloadLink } Else { "NA" });
KnownIssues=$(If ((!($NoIssuesKnown))) { "Known Issues with update" } Else { "No known issues" });
Issue=$Issue;
Workaround=$($Workaround | Out-String);
} # End New-Object -Property
Remove-Variable -Name DownloadLink,OS,OSVersion,OSBuild,KnownIssueCheck,UnknownIssueCheck,KBReleaseNotes,ReleaseNotesUri,Workaround,Issue,PTag,PTags,Match -Force -ErrorAction SilentlyContinue -Verbose:$False -WhatIf:$False
} Else {
ForEach ($OS in $OSes) {
Set-Variable -Name OSVersion -Value $OS -Force -WhatIf:$False
Set-Variable -Name OperatingSystem -Value ($OS -Split "Version ")[0] -Force -WhatIf:$False
If ($OperatingSystem -notlike ".NET Framework*") {
$OperatingSystem = $OperatingSystem.Split(',')[0].Replace(' SP1', '').Replace(' SP2', '').Replace("Windows Server 2008 R2 and Windows Server 2008", "Windows Server 2008 R2").Replace('Windows 11 Version 22H2' ,'Windows 11').Replace('Windows 10 Version 21H2 and Windows 10 Version 22H2', 'Windows 10').Trim()
$DownloadLink = Get-KBDownloadLink -ArticleId $KB -OperatingSystem $OperatingSystem -Architecture "x64" -Verbose:$False -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
} # End If
If (!($NoIssuesKnown)) {
$Match = ($KBReleaseNotes.RawContent | Select-String -Pattern '<tbody>(.|\n)*?<\/tbody>').Matches.Value
If ($Match -like "*WPF*") {
$Match = ($KBReleaseNotes.RawContent | Select-String -Pattern '<tbody>(.|\n)*?<\/tbody>' -AllMatches).Matches.Value
$PTags = ($Match | Select-String -Pattern '<p>(.|\n)*?<\/p>' -AllMatches).Matches.Value | Where-Object -FilterScript { $_ -notlike '<p></p>' -and $_ -notmatch ">Release Channel<" -and $_ -notmatch ">WPF<" -and $_ -notmatch ">Available<" -and $_ -notmatch ">Resolution<" -and $_ -notmatch ">Next Step<" -and $_ -notmatch ">Product Version<" -and $_ -notmatch ">Symptom<" -and $_ -like "*Windows *" }
$OSV = ($OSVersion -Split "Version ")[-1]
For ($i = 0; $i -lt $PTags.Count; $i++) {
If ($Next) {
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Issue variable is true while `$i = $i"
$Issue = $PTags[$i].Replace("<p>", "").Replace("</p>", "")
$Next = $False
} # End If
If ($YourOtherNext) {
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Workaround variable is set while `$i = $i"
$Workaround = $PTags[$i].Replace("<p>", "").Replace("</p>", "")
Break
} # End If
If ($PTags[$i] -like "*, version $($OSV.Split("H")[0])H*") {
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Next and OtherNext variables set TRUE while `$i = $i"
$Next = $True
$OtherNext = $True
} Else {
If ($OtherNext) {
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Next variable is set to FALSE and OtherNext variable set TRUE while `$i = $i"
$YourOtherNext = $True
} # End If
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Next variable is set to FALSE while `$i = $i"
$Next = $False
} # End If Else
If ($PTags[$i] -like "*<p>Windows Update and Microsoft Update</p>*") {
Write-Verbose -Message "[D] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Break statement reached while `$i = $i on WIndows Update and Microsoft Update match"
Break
} # End If
} # End For
Remove-Variable -Name Next,OtherNext,YourOtherNext -WhatIf:$False -Force -Verbose:$False -ErrorAction SilentlyContinue
} Else {
$Match = ($KBReleaseNotes.RawContent | Select-String -Pattern '<tbody>(.|\n)*?<\/tbody>').Matches.Value
$PTags = ($Match | Select-String -Pattern '<p>(.|\n)*?<\/p>' -AllMatches).Matches.Value | Where-Object -FilterScript { $_ -notlike '<p></p>' -and $_ -notmatch ">Symptom<" -and $_ -notmatch ">Workaround<" -and $_ -notmatch ">Next step<" -and $_ -notlike '<p></p>' -and $_ -notlike "*>Symptom<*" -and $_ -notlike "*>Workaround<*" -and $_ -notlike "*>Next step<*" }
$Issue = $PTags[0].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ') + $(If ($PTags[1] -like "*>Note*") { "<br>$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))" } )
$Workaround = ($PTags | Where-Object -FilterScript { $_ -notlike $PTags[0]}).Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ')
If ($Issue -like "*Symptom*") {
$Issue = $PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ') + $(If ($PTags[1] -like "*>Note*") { "<br>$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))" } )
$Workaround = ($PTags | Where-Object -FilterScript { $_ -notlike $PTags[0] -and $_ -notlike $PTags[1]}).Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ')
If ($Issue -like "*Next step*") {
$Issue = $PTags[2].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ') + $(If ($PTags[1] -like "*>Note*") { "<br>$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))" } )
$Workaround = ($PTags | Where-Object -FilterScript { $_ -notlike $PTags[0] -and $_ -notlike $PTags[1] -and $_ -notlike $PTags[2]}).Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' ')
} # End If
} # End If
If ($PTags[1] -like "*>Note*") {
$Workaround = $Workaround.Replace("$($PTags[1].Replace('<p>', '').Replace('</p>', '').Replace('<br>', ' '))", "")
} # End If
} # End If Else
} # End If
New-Object -TypeName PSCustomObject -Property @{
KB=$KB;
OperatingSystem=$OSVersion;
Reference=$ReleaseNotesUri;
DownloadLink=$(If ($DownloadLink) { $DownloadLink } Else { "NA" });
KnownIssues=$(If ((!($NoIssuesKnown))) { "Known Issues with update" } Else { "No known issues" });
Issue=$Issue;
Workaround=$($Workaround | Out-String);
} # End New-Object -Property
Remove-Variable -Name DownloadLink,OS,OSVersion,OSBuild,KnownIssueCheck,UnknownIssueCheck,KBReleaseNotes,ReleaseNotesUri,Workaround,Issue,PTag,PTags,Match -Force -ErrorAction SilentlyContinue -Verbose:$False -WhatIf:$False
} # End ForEach
} # End If
} # End ForEach
Return $Output
} # End Function Get-WindowsUpdateIssue
Try {
Test-Path -Path $LogoFilePath.FullName -ErrorAction Stop | Out-Null
Try {
$ImageBase64 = [Convert]::ToBase64String((Get-Content -Path $LogoFilePath -Encoding Byte))
} Catch {
$ImageBase64 = [Convert]::ToBase64String((Get-Content -Path $LogoFilePath -AsByteStream))
} # End Try Catch
} Catch {
Write-Verbose -Message "[v] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Company logo file was not assigned"
} # End Try Catch
Write-Verbose -Message "[v] $(Get-Date -Format 'MM-dd-yyyy hh:mm:ss') Obtaining update information from Microsoft"
$PatchTuesday = Get-DayOfTheWeeksNumber -DayOfWeek Tuesday -WhichWeek 2 -Verbose:$False
$Results = Get-WindowsUpdateIssue -Verbose:$False
$IssueKBs = $Results | Where-Object -Property "KnownIssues" -eq "Known issues with update"
If ($IssueKBs.KB.Count -ge 1) {
$PlaceHolder = $IssueKBs | Select-Object -First 1 -ExpandProperty KB
$EmailInfo = $IssueKBs
} Else {
$PlaceHolder = $Results | Select-Object -First 1 -ExpandProperty KB
$EmailInfo = $Results
} # End If Else
$RawJson = (($Results | Select-Object -Property 'KB','OperatingSystem','KnownIssues',@{Label='Reference'; Expression={"<a href='$($_.Reference)' target='_blank'>$($_.KB) Release Notes</a>"}},@{Label='DownloadLink'; Expression={If ((!($_.DownloadLink)) -or $_.DownloadLink -ne "NA") { "<a href='$($_.DownloadLink)' target='_blank'>Download $($_.KB)</a>"} Else { $_.DownloadLink }}} | ConvertTo-Json -Depth 3).Replace('\u0000', '')) -Split "`r`n"
$IssueJson = (($Results | Select-Object -Property 'KB','OperatingSystem','Issue','Workaround' | ConvertTo-Json -Depth 3).Replace('\u0000', '')) -Split "`r`n"
If ($RawJson[0] -eq '[') {
$FormatedJson = .{
'const response = {
"kbdata": ['
$RawJson | Select-Object -Skip 1
}
$FormatedJson[-1] = ']};'
} Else {
$FormatedJson = .{
'const response = {
"kbdata": ['
$RawJson | Select-Object -Skip 1
}
$FormatedJson[-1] = ']};' # replace last Line
} # End If Else
If ($IssueJson[0] -eq '[') {
$IssueFormatedJson = .{
'var issuedata = ['
$IssueJson | Select-Object -Skip 1
}
$IssueFormatedJson[-1] = '];'
} Else {
$IssueFormatedJson = .{
'var issuedata = {'
$IssueJson | Select-Object -Skip 1
}
$IssueFormatedJson[-1] = '};' # replace last Line
} # End If Else
$EmailCss = @"
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma">
<meta http-equiv="Expires" content="0">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Windows Update Known Issues Report</title>
<style type="text/css">
@charset "utf-8";
body {
position: realtive;
margin: auto;
width: 975px;
background-color: $HtmlBodyBackgroundColor;
}
h1 {
font-family: Arial, Helvetica, sans-serif;
background-color: $H1BackgroundColor;
font-size: 28px;
text-align: center;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: $H1BorderColor;
background: $H1BackgroundColor;
background: linear-gradient($H3FadeBackgroundColor, $H1BackgroundColor);
color: $H1TextColor;
padding: 10px 15px;
vertical-align: middle;
}
h2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
color: $H2TextColor;
text-align: left;
}
h3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 22px;
text-align: center;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: $H3BorderColor;
background: $H3BackgroundColor;
background: linear-gradient($H3FadeBackgroundColor, $H3BackgroundColor);
color: $H3TextColor;
padding: 10px 15px;
vertical-align: middle;
}
p {
font-family: Arial, Helvetica, sans-serif;
color: $HtmlBodyTextColor;
padding:
}
table {
color: $TableTextColor;
font-family: Arial, Helvetica, sans-serif;
font-size:12px;
border-width: 1px;
border-color: $TableBorderColor;
border-collapse: collapse;
position: relative;
margin: auto;
width: 975px;
}
th {
border-width: 1px;
padding: 8px;
border-style: solid;