Загрузка обновлений Windows с сервера WSUS - PullRequest
0 голосов
/ 06 декабря 2018

Моя цель: клиентский ПК (Windows 10 Pro) автоматически загружает обновления Windows с сервера WSUS и устанавливает их с помощью Powershell.

Моя ситуация: клиентский ПК присоединился к домену AD и объекту групповой политики, которыйобозначает IP-адрес сервера WSUS (http://192.168.1.200:8530) применяется к ПК.

Моя проблема: я создал следующий скрипт Powershell и запустил его с правами администратора на ПК.

# 1. Start Windows Update session
$updateSession = New-Object -com Microsoft.Update.Session

# 2. Search Windows Updates
$searcher = $updateSession.CreateUpdateSearcher()
$searchResult = $searcher.search("IsInstalled=0 and Type='software'")

# 3. Show the result of Windows Updates
Write-Host -ForegroundColor Cyan "Downloadable Windows Updates are as follows:"
$searchResult.Updates | % { $_.title -replace ".*(KB\d+).*", "`$1`t$&" }

# 4. Show the result of Windows Updates which are automatically downloadable
$updatesToDownload = New-Object -com Microsoft.Update.UpdateColl
$searchResult.Updates | ? { -not $_.InstallationBehavior.CanRequestUserInput } | ? { $_.EulaAccepted } | % { [void]$updatesToDownload.add($_) }

# 5. Download
Write-Host -ForegroundColor Cyan "Downloading updates..."
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloader.Download()

# 6. Show the result of the downloaded updates
Write-Host -ForegroundColor Cyan "Download is finished."
$updatesToInstall = New-Object -com Microsoft.Update.UpdateColl
$searchResult.Updates | ? { $_.IsDownloaded } | % { [void]$updatesToInstall.add($_) }

# 7. Install
Write-Host -ForegroundColor Cyan "Installing Updates..."
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $updatesToInstall
$installationResult = $installer.Install()

# 8. Show the result of installation (ResultCode 2 is success, over 3 is fail.)
$installationResult

# 9. reboot
Restart-Computer

Вышеприведенный скрипт казался работающим, но оказалось, что клиенты загружали обновления из Интернета (может быть, с сайта Microsoft Update?). Фактически, даже когда я выключал сервер WSUS, этот скрипт работал. Загрузка и установка прошли успешно.

Мой вопрос: какая часть скрипта неверна? Или я не могу загрузить обновления из WSUS с помощью Powershell?

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