Commit 46080048 authored by Seng Lin Shee's avatar Seng Lin Shee
Browse files

Fix syntax that prevents update discovery

The Count and other properties of the items were not accessible if there
is only 1 item in the array. This fix ensures that all properties can be
read.

This was tested and discovered in Windows Server 2012 R2. This results
in a longer update time, which proves that there are now more updates
being installed.
parent 189b51e8
......@@ -60,9 +60,9 @@ function Install-WindowsUpdates() {
LogWrite "Evaluating Available Updates with limit of $($MaxUpdatesPerCycle):"
$UpdatesToDownload = New-Object -ComObject 'Microsoft.Update.UpdateColl'
$script:i = 0;
$CurrentUpdates = $SearchResult.Updates | Select-Object
$CurrentUpdates = $SearchResult.Updates
while($script:i -lt $CurrentUpdates.Count -and $script:CycleUpdateCount -lt $MaxUpdatesPerCycle) {
$Update = $CurrentUpdates[$script:i]
$Update = $CurrentUpdates.Item($script:i)
if (($Update -ne $null) -and (!$Update.IsDownloaded)) {
[bool]$addThisUpdate = $false
if ($Update.InstallationBehavior.CanRequestUserInput) {
......@@ -230,3 +230,4 @@ if ($global:MoreUpdates -eq 1) {
} else {
Check-ContinueRestartOrEnd
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment