CLS $MyDate=Get-Date -Format "yyyy-MM" Write-Host "KB List for Month `t `t $MyDate" Write-Host `n #------------------------------- Windows 10 22H2 ----------------------------------- $Date=Get-Date -Format "MM" (Invoke-WebRequest -Uri https://www.catalog.update.microsoft.com/Search.aspx?q=Cumulative%20Update%20for%20Windows%2010%20Version%2022H2%20).Content | Out-File C:\temp\10C-$X.txt #Export Data Out to File $Lines= Get-Content C:\temp\10C-$X.txt $Line1=@() #Loop Through Each File to Get KB Output Foreach($Line in $Lines){ If($Line -like "*(KB*"){ if(($Line -like "*Cumulative Update for Windows 10 Version 22H2 for x64-based Systems*") -and ($Line -notlike "*Dynamic*") ){ $Line1+=$Line.Trim("2023-$Date Cumulative Update for Windows 10 Version 22H2 for x64-based Systems").Replace("(","").Replace(")","") } } } Write-Host "Windows 10 22H2 `t $Line1" "2023-$Date `t Windows 10 22H2 `t $Line1" | Out-File C:\temp\Patch-KB.txt Write-Host `n #------------------------------- 2016 Server ----------------------------------- $Date=Get-Date -Format "MM" (Invoke-WebRequest -Uri https://www.catalog.update.microsoft.com/Search.aspx?q=2023-$Date Cumulative Update for Windows Server 2016 for x64-based Systems).Content | Out-File C:\temp\2016C-$X.txt #Export Data Out to File $Lines= Get-Content C:\temp\2016C-$X.txt #Loop Through Each File to Get KB Output Foreach($Line in $Lines){ If($Line -like "*(KB*"){ $text=$Line $2016=$text.Trim(" 2023-$Date Cumulative Update for Windows Server 2016 for x64-based Systems").Replace("(","").Replace(")","") Write-Host "Windows Server 2016 `t $2016" "2023-$Date `t Windows Server 2016 `t $2016" | Out-File C:\temp\Patch-KB.txt -Append } } Write-Host `n #------------------------------- 2019 Server ----------------------------------- (Invoke-WebRequest -Uri https://www.catalog.update.microsoft.com/Search.aspx?q=2023-$Date Cumulative Update for Windows Server 2019 for x64-based Systems).Content | Out-File C:\temp\2019C-$X.txt #Export Data Out to File $Lines= Get-Content C:\temp\2019C-$X.txt #Loop Through Each File to Get KB Output Foreach($Line in $Lines){ If($Line -like "*(KB*"){ $text=$Line $2019=$text.Trim("2023-$Date Cumulative Update for Windows Server 2019 for x64-based Systems").Replace("(","").Replace(")","") Write-Host "Windows Server 2019 `t $2019" "2023-$Date `t Windows Server 2019 `t $2019" | Out-File C:\temp\Patch-KB.txt -Append } } Write-Host `n #------------------------------- 2019 Server ----------------------------------- (Invoke-WebRequest -Uri https://www.catalog.update.microsoft.com/Search.aspx?q=2023-$Date Cumulative Update for Microsoft server operating system version 21H2 for x64-based Systems).Content | Out-File C:\temp\2022C-$X.txt #Export Data Out to File $Lines= Get-Content C:\temp\2022C-$X.txt #Loop Through Each File to Get KB Output Foreach($Line in $Lines){ If($Line -like "*(KB*"){ $text=$Line $2022=$text.Trim("2023-$Date Cumulative Update for Microsoft server operating system version 21H2 for x64-based Systems").Replace("(","").Replace(")","") Write-Host "Windows Server 2022 `t $2022" "2023-$Date `t Windows Server 2022 `t $2022" | Out-File C:\temp\Patch-KB.txt -Append } } Write-Host `n Invoke-Item C:\temp\Patch-KB.txt