PowerShell до шага в цикле - PullRequest
       1

PowerShell до шага в цикле

0 голосов
/ 23 января 2019

Я пытаюсь написать скрипт, который обновит Windows с помощью PSWindowsUpdate.Я хочу, чтобы скрипт постоянно запускал PSWindowsUpdate, пока не осталось больше обновлений для установки.Сценарий завершается с ошибкой при выполнении последней команды "before", указывающей:

until : The term 'until' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\Users\user\Desktop\Install-WindowsUpdates-Edit.ps1:63 char:2
+ } until ($updates -eq $null)
+   ~~~~~
    + CategoryInfo          : ObjectNotFound: (until:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Там есть несколько строк выше без проблем.Все скобки, которые я вижу, заполнены {} каждая.Я не понимаю, почему происходит эта ошибка.

<#
.SYNOPSIS
This script will automatically install all avaialable windows updates on a device and will automatically reboot if needed, after reboot, windows updates will continue to run until no more updates are available. Pilfered     from: https://www.altaro.com/msp-dojo/powershell-windows-updates/#comment-272
#>

"Installing NuGet Package Provider"

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

"Installing the PSWindowsUpdate module"

Install-Module PSWindowsUpdate -Force

# retrieves a list of available updates
"Checking for new updates"

$updates = Invoke-Command -ScriptBlock {Get-WUList -Verbose}

# counts how many updates are available
$updatenumber = ($updates.kb).Count

# if there are available updates proceed with installing the updates and then reboot
if ($updates -ne $null) {
    # Command to install windows updates, creates a scheduled task on the computer
    $Script = {
        Import-Module PSWindowsUpdate;
        Get-WindowsUpdate -AcceptAll -Install | Out-File C:\PSWindowsUpdate.log
    }

    Invoke-WUJob -Script $Script -Confirm:$false -RunNow

    # Show update status until the amount of installed updates equals the same as the amount of updates available

    sleep -Seconds 30

    do {
        $updatestatus = Get-Content c$\PSWindowsUpdate.log

        "Currently processing the following update:"
        Get-Content c$\PSWindowsUpdate.log | select-object -last 1

        sleep -Seconds 10

        $ErrorActionPreference = 'SilentlyContinue'
        $installednumber = ([regex]::Matches($updatestatus, "Installed" )).Count
        $ErrorActionPreference = 'Continue'
    } until ($installednumber -eq $updatenumber)

    # restarts the remote computer and waits till it starts up again

    "restarting computer"

    Restart-Computer -Wait -Force
} until ($updates -eq $null) #ERROR THROWN HERE

# removes schedule task from computer
#Invoke-Command -ScriptBlock {Unregister-ScheduledTask -TaskName PSWindowsUpdate -Confirm:$false}

Remove-Module -Name "PSWindowsUpdate"

"Windows is now up to date"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...