从WSUS服务器下载Windows更新

时间:2018-12-06 03:11:47

标签: windows powershell windows-update

我的目标: 客户端PC(Windows 10 Pro)使用Powershell自动从WSUS服务器下载Windows Update并进行安装。

我的情况: 客户端PC已加入AD域,并且将指定WSUS服务器IP地址(http://192.168.1.200:8530)的GPO应用于PC。

我的问题: 我创建了以下Powershell脚本,并在PC上以管理员身份运行它。

# 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

上面的脚本似乎有效,但是事实证明客户端是从Internet(可能是Microsoft Update Site?)下载更新的。实际上,即使我关闭WSUS服务器,该脚本也能正常工作。下载和安装成功。

我的问题: 脚本的哪一部分是错误的?还是无法使用Powershell从WSUS下载更新?

0 个答案:

没有答案