是否有任何批处理脚本或命令行命令可以在多个远程服务器上自动执行 Windows 更新(可能通过 psexec)?不喜欢使用 VB 脚本,但如果有可用的脚本,那也可以。谢谢。
答案1
取决于你想怎么做。如果你想要一个更像批处理的 psexec 方法,你需要研究一下我以前见过的共享软件 CLI 实用程序。说实话,我从来没有亲自测试过它,wuinstall。我看到一些 Windows 类型的 IT 杂志上的文章,所以我怀疑你不是第一个。有一个免费软件和专业版,但我不能说许可限制是什么。
如果你能理解脚本,我知道这个 Winboxen 系统管理员 lucifist 写了一个 PowerShell 脚本来执行您正在寻找什么。
######################################################################################################################################
# Windows Update through Powershell (No Forms) v1.0 ######################################################################################################################################
clear-host
Write-host "Starting Update Process..." -foregroundcolor blue
Write-host ""
$UpdateSession = New-Object -com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$SearchResult = $UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0")
$UpdateLowNumber = 0
$UpdateHighNumber = 1
$NumberofUpdates = $searchResult.Updates.Count
while ($UpdateHighNumber -le $NumberofUpdates) {
$UpdatesToDownload = New-Object -com Microsoft.Update.UpdateColl
$Update = $searchResult.Updates.Item($UpdateLowNumber)
if ($Update.EulaAccepted -eq 0) {$Update.AcceptEula()}
[void]$UpdatesToDownload.Add($Update)
$Downloader = $UpdateSession.CreateUpdateDownloader()
$Downloader.Updates = $UpdatesToDownload
[void]$Downloader.Download()
$UpdatesToInstall = New-Object -com Microsoft.Update.UpdateColl
[void]$UpdatesToInstall.Add($Update)
$Title = $update.Title
$KBArticleIDs = $update.KBArticleIDs
$SecurityBulletinIDs = $update.SecurityBulletinIDs
$MsrcSeverity = $update.MsrcSeverity
$LastDeploymentChangeTime = $update.LastDeploymentChangeTime
$MoreInfoUrls = $update.MoreInfoUrls
Write-host "Installing Update $UpdateHighNumber of $NumberofUpdates"
Write-host "Title: $Title"
if ($KBArticleIDs -ne "") {Write-host "KBID: $KBArticleIDs"}
if ($SecurityBulletinIDs -ne "") {write-host "Security Bulletin: $SecurityBulletinIDs"}
if ($MsrcSeverity -eq "Critical") {Write-host "Rating: $MsrcSeverity" -foregroundcolor red} else {Write-host "Rating: $MsrcSeverity"}
if ($LastDeploymentChangeTime -ne "") {Write-host "Dated: $LastDeploymentChangeTime"}
if ($MoreInfoUrls -ne "") {Write-host "$MoreInfoUrls"}
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
Write-host "--------------------------------------------"
if ($InstallationResult.ResultCode -eq "2") {Write-host " Installation Succeeded" -foregroundcolor green} else {Write-host " INSTALLATION FAILED, check event log for details" -foregroundcolor red}
if ($InstallationResult.RebootRequired -eq "False") {Write-host " Reboot not required" -foregroundcolor green} else {Write-host " REBOOT REQUIRED" -foregroundcolor red}
Write-host "--------------------------------------------"
Write-host ""
Write-host ""
$Title = ""
$KBArticleIDs = ""
$SecurityBulletinIDs = ""
$MsrcSeverity = ""
$LastDeploymentChangeTime = ""
$MoreInfoUrls = ""
$UpdateLowNumber = $UpdateLowNumber + 1
$UpdateHighNumber = $UpdateHighNumber + 1
if ($ProgressValue -lt $NumberofUpdates) {$ProgressValue = $ProgressValue + 1}
}
$ComputerStatus = New-Object -com Microsoft.Update.SystemInfo
if ($ComputerStatus.RebootRequired -eq 1) {cmd /c $env:WinDir\System32\Shutdown.exe -r -f -t 10 -c "Patching Complete."}
如果您仔细查看此脚本,就会发现您正在打开 COM 对象等。因此,您要么需要烘焙自己的二进制文件或其他人的非 MSFT 代码(例如 Wuinstall),要么在 VBScript 中执行相同数量的脚本。您说的是 Win23k Server,所以我不确定您是否安装了 PS。如果没有,则有TechNet 文档治愈你的病痛。
最重要的是,Google 是你的朋友。在此发帖之前请记住这一点。:-)