Windows-Server-2008

防止伺服器在自動更新後重新啟動

  • August 20, 2015

在我們照顧客戶的方式上,工作已經開始了一個新的焦點,試圖更加積極主動,而不僅僅是對問題做出反應。此重點的一部分是確保伺服器是最新的。我們已經部署了一個 GP 來更新伺服器(電腦配置 > 管理模板 > Windows 組件 > Windows 更新 > 配置自動更新)。

我們現在需要一種方法來確保伺服器僅在特定時間重新啟動,而不是在它們完成時重新啟動。我在這裡找到了我認為的答案,但它僅適用於 Server 2003,而不是我需要的 2008 和 2012。有沒有類似的GP可以用?計劃是讓伺服器在一周內自動掃描、下載和安裝更新,任何需要重新啟動才能安裝的東西都將在周末發生。

這裡的訣竅是不要讓 Windows 更新通過自動更新機制進行安裝。您可以將其設置為自動下載,但對於自動安裝,除非有使用者登錄到系統,否則無法阻止重啟計時器觸發,例如對於計劃的自動更新安裝策略,使用登錄使用者不自動重啟. 由於這是針對伺服器的,我將假設這不是預設情況,並且沒有人登錄並不意味著目前不需要機器的資源。

設置將觸發安裝更新的計劃任務,並在更新完成或其他操作時報告,以便您知道電腦應該重新啟動。

我很快修改了此處找到的腳本以滿足您的需求:

#      Author: Gregory Strike
#     Website: www.GregoryStrike.com
#        Date: 02-19-2010
# Information: This script was adapated from the WUA_SearchDownloadInstall.vbs VBScript from Microsoft.  It uses the
#              Microsoft.Update.Session COM object to query a WSUS server, find applicable updates, and install them.

# < --- SNIP --- >

$UpdateSession = New-Object -Com Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()

$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and Type='Software'")

$UpdatesToInstall = New-Object -Com Microsoft.Update.UpdateColl

For ($X = 0; $X -lt $SearchResult.Updates.Count; $X++){
   $Update = $SearchResult.Updates.Item($X)
   If ($Update.IsDownloaded) {
       $Null = $UpdatesToInstall.Add($Update)        
   }
}


If ($Install.ToUpper() -eq "Y" -or $Install.ToUpper() -eq "YES"){
   Write-Host("")
   Write-Host("Installing Updates...") -Fore Green

   $Installer = $UpdateSession.CreateUpdateInstaller()
   $Installer.Updates = $UpdatesToInstall

   $InstallationResult = $Installer.Install()

   $ResultsBody = "List of Updates Installed with Results:"
   For ($X = 0; $X -lt $UpdatesToInstall.Count; $X++){
       $ResultsBody = $ResultsBody + "`r`n" + $UpdatesToInstall.Item($X).Title + ": " + $InstallationResult.GetUpdateResult($X).ResultCode
   }

   If ($InstallationResult.RebootRequire -eq $True){
       Send-MailMessage -From server@example.com -To admin@example.com -Subject "Server has installed updates that require a reboot" -Body 
   } else {
       Send-MailMessage -From server@example.com -To admin@example.com -Subject "Server has installed updates that do not require a reboot" -Body
   }
}

注意:

您也可以使用連結的原始腳本並對其進行修改以進行檢測和下載,在這種情況下,最好禁用“配置自動更新”策略。

附錄: Microsoft 腳本中心中

有一個Windows Update PowerShell 模組,它提供了輕鬆編寫您自己的 Windows Update 腳本所需的功能。其實在google第一頁有很多不錯的資源(在寫這篇文章的時候)供搜尋:powershell windows update

引用自:https://serverfault.com/questions/715429