Commit d1c13e67 authored by Ken Sykora's avatar Ken Sykora
Browse files

Fixed errors with update script

parent fe72620b
...@@ -47,11 +47,12 @@ function Check-ContinueRestartOrEnd() { ...@@ -47,11 +47,12 @@ function Check-ContinueRestartOrEnd() {
function Install-WindowsUpdates() { function Install-WindowsUpdates() {
$script:Cycles++ $script:Cycles++
Write-Host 'Evaluating Available Updates with limit of $($global:MaxUpdatesPerCycle):' Write-Host "Evaluating Available Updates with limit of $($global:MaxUpdatesPerCycle):"
$UpdatesToDownload = New-Object -ComObject 'Microsoft.Update.UpdateColl' $UpdatesToDownload = New-Object -ComObject 'Microsoft.Update.UpdateColl'
$script:i = 0; $script:i = 0;
while($script:i -lt $SearchResult.Updates.Count -and $script:CycleUpdateCount -lt $global:MaxUpdatesPerCycle) { $CurrentUpdates = $SearchResult.Updates | Select-Object
$Update = $SearchResult.Updates[$script:i] | Select-Object while($script:i -lt $CurrentUpdates.Count -and $script:CycleUpdateCount -lt $global:MaxUpdatesPerCycle) {
$Update = $CurrentUpdates[$script:i]
if (($Update -ne $null) -and (!$Update.IsDownloaded)) { if (($Update -ne $null) -and (!$Update.IsDownloaded)) {
[bool]$addThisUpdate = $false [bool]$addThisUpdate = $false
if ($Update.InstallationBehavior.CanRequestUserInput) { if ($Update.InstallationBehavior.CanRequestUserInput) {
...@@ -157,7 +158,8 @@ function Check-WindowsUpdates() { ...@@ -157,7 +158,8 @@ function Check-WindowsUpdates() {
$script:SearchResult = $script:UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0") $script:SearchResult = $script:UpdateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
$script:successful = $TRUE $script:successful = $TRUE
} catch { } catch {
Write-Error "Search call to UpdateSearcher was unsuccessful. Retrying in 10s." Write-Host $_.Exception | Format-List -force
Write-Host "Search call to UpdateSearcher was unsuccessful. Retrying in 10s."
$script:attempts = $script:attempts + 1 $script:attempts = $script:attempts + 1
Start-Sleep -s 10 Start-Sleep -s 10
} }
......
Supports Markdown
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