有没有办法找出Windows服务器(2003,2008)是否下载了Microsoft Windows更新,并且只是等待用户确认“安装更新并重新启动服务器”?
我们使用WSUS和SSCM收集和发布更新,大部分服务器在周日早上自动安装,主要是开发和testing服务器。
我们已经将我们重要的生产服务器设置为只能手动安装,但偶尔一些服务器不会手动重启(人们忘记了!)
这将是很好,如果有一些方法(PowerShell脚本,WMI查询,一些魔术命令),我可以用来计数或发现是否有更新挂起。
这是我写的脚本。 它会告诉你:
用法示例: C:\> cscript ServerPendingUpdates.vbs myserver01 myserver02
Connecting to myserver01 to check software update status... myserver01 has 2 updates pending installation myserver01 WILL need to be rebooted to complete the installation of these updates. myserver01 is waiting for a REBOOT to complete a previous installation. <snip>
脚本:
'# '# ServerPendingUpdates.vbs '# '# Usage: cscript ServerPendingUpdates.vbs {servername} {servername} {servername} {servername} '# If no {servername} specified then 'localhost' assumed '# '# To do: Error handling '# Option Explicit Dim strServer : strServer = GetArgValue(0,"localhost") '# '# Loop through the input parameters for each server '# Dim i For i = 0 To WScript.Arguments.Count - 1 CheckServerUpdateStatus GetArgValue(i,"localhost") 'strServer Next WScript.Quit(0) Function CheckServerUpdateStatus( ByVal strServer ) WScript.Echo vbCRLF & "Connecting to " & strServer & " to check software update status..." Dim blnRebootRequired : blnRebootRequired = False Dim blnRebootPending : blnRebootPending = False Dim objSession : Set objSession = CreateObject("Microsoft.Update.Session", strServer) Dim objUpdateSearcher : Set objUpdateSearcher = objSession.CreateUpdateSearcher Dim objSearchResult : Set objSearchResult = objUpdateSearcher.Search(" IsAssigned=1 and IsHidden=0 and Type='Software'") '# '# '# Dim i, objUpdate Dim intPendingInstalls : intPendingInstalls = 0 For i = 0 To objSearchResult.Updates.Count-1 Set objUpdate = objSearchResult.Updates.Item(I) If objUpdate.IsInstalled Then If objUpdate.RebootRequired Then blnRebootPending = True End If Else intPendingInstalls = intPendingInstalls + 1 'If objUpdate.RebootRequired Then '### This property is FALSE before installation and only set to TRUE after installation to indicate that this patch forced a reboot. If objUpdate.InstallationBehavior.RebootBehavior <> 0 Then '# http://msdn.microsoft.com/en-us/library/aa386064%28v=VS.85%29.aspx '# InstallationBehavior.RebootBehavior = 0 Never reboot '# InstallationBehavior.RebootBehavior = 1 Must reboot '# InstallationBehavior.RebootBehavior = 2 Can request reboot blnRebootRequired = True End If End If Next WScript.Echo strServer & " has " & intPendingInstalls & " updates pending installation" If blnRebootRequired Then WScript.Echo strServer & " WILL need to be rebooted to complete the installation of these updates." Else WScript.Echo strServer & " WILL NOT require a reboot to install these updates." End If '# '# '# If blnRebootPending Then WScript.Echo strServer & " is waiting for a REBOOT to complete a previous installation." End If End Function '# '# '# Function GetArgValue( intArgItem, strDefault ) If WScript.Arguments.Count > intArgItem Then GetArgValue = WScript.Arguments.Item(intArgItem) Else GetArgValue = strDefault End If End Function
你可以使用wuinstall 。 它有一个/search开关,以查看是否有更新未决。 您可以使用psexec远程执行。
另一个select是parsing%windir%\ windowsupdate.log,并寻找这样的东西:#警告:安装调用完成,需要重启=是,错误= 0x00000000
我使用由Rob Dunn&贡献者撰写的UpdateHf.vbs脚本。 因为它在所报告的主机上本地运行,所以我的所有机器上都安装了它。 我创build了一个MSI包,并通过GPO推送它。
为了触发报告,我有一个powershell脚本的集合,在OU值得服务器上创build计划任务,每台计算机都计划在本地运行UpdateHF.vbs,并将结果发送给我。 然后,我使用sorting规则对生成的电子邮件进行颜色编码,这是基于在报告中search不同的文本。
UpdateHF.vbs基本上是微软发布的自动更新API的封装,所以有些挖掘我打赌你可以找出脚本处理“Reboot Pending”检查的位,如果你想要的只是一个布尔重启状态标志。
下面是我的系统的核心:Powershell在schtasks.exe的调用中填充variables。 (请注意,如果密码有复杂的字符,则需要使用反色标签将其转义。)
schtasks.exe /create /F /S $TargetHost /tn Patch /sc once /st $TargetTime /sd $StartDate /ru User /rp Password /tr "$WinPath\system32\cscript.exe $WinPath\UpdateHF.vbs $UpdateArgs"
作为远程框的pipe理员,打开一个MMC,然后添加事件查看器pipe理单元。 select“另一台计算机”(与“本地计算机”的默认设置相对应,然后input目标计算机名称,然后按事件types进行过滤,只能看到所需的名称),称为“Windows更新代理”
“安装就绪:以下更新已下载并准备安装。此计算机当前计划在[date]安装这些更新…”
在2012 R2服务器去控制面板,点击Windows更新。 在页面的左侧面板上单击“检查更新”链接,您将看到挂起更新列表(尚未安装在服务器上)。 点击任何一个链接,你将看到整个(可选的和强制性的)列表以及每个链接的简要描述。
请注意,自动安装更新必须打开。