远程触发 WSUS 下载的更新安装

Zyp*_*her 7 windows-server-2003 wsus update

这已经困扰我一段时间了。我们将我们的服务器设置为仅下载 Windows 更新,以便在我们的双月补丁窗口之一中安装它们。在此期间,我一直在寻找一种在服务器上远程触发安装的方法,这样我就不必登录一百个或更多服务器并单击“立即安装更新”气球。

有人知道远程触发更新安装的方法吗?

Zyp*_*her 6

我终于弄明白了。有一个(几乎没有)记录的 Windows 更新 API,您可以使用它来触发这些类型的事情。我使用了这里找到的脚本的修改形式,它与您可以获得的文档尽可能接近。

我将其修改如下,取出下载部分 - 因为我使用 GPO 和 WSUS 控制下载,以及所有提示。然后,如果更新需要,我插入了一些代码来重新启动盒子。

Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
WScript.Echo "Searching for updates..." & vbCRLF

Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")


WScript.Echo "List of applicable items on the machine:"

For I = 0 To searchResult.Updates.Count-1
    Set update = searchResult.Updates.Item(I)
    WScript.Echo I + 1 & "> " & update.Title
Next

If searchResult.Updates.Count = 0 Then
    WScript.Echo "There are no applicable updates."
    WScript.Quit
End If


Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

WScript.Echo  vbCRLF & _
"Creating collection of downloaded updates to install:" 

For I = 0 To searchResult.Updates.Count-1
    set update = searchResult.Updates.Item(I)
    If update.IsDownloaded = true Then
       WScript.Echo I + 1 & "> adding:  " & update.Title 
       updatesToInstall.Add(update) 
    End If
Next

'WScript.Echo  vbCRLF & "Would you like to install updates now? (Y/N)"
'strInput = WScript.StdIn.Readline
'WScript.Echo 

'If (strInput = "N" or strInput = "n") Then 
'   WScript.Quit
'ElseIf (strInput = "Y" or strInput = "y") Then
    WScript.Echo "Installing updates..."
    Set installer = updateSession.CreateUpdateInstaller()
    installer.Updates = updatesToInstall
    Set installationResult = installer.Install()

    'Output results of install
    WScript.Echo "Installation Result: " & _
    installationResult.ResultCode 
    If (installationResult.RebootRequired = True) Then
        Set RebootShell = WScript.CreateObject("Wscript.Shell")
        RebootShell.Run "shutdown.exe -r -t 0"
    End If

    WScript.Echo "Reboot Required: " & _ 
    installationResult.RebootRequired & vbCRLF 
    WScript.Echo "Listing of updates installed " & _
     "and individual installation results:" 

    For I = 0 to updatesToInstall.Count - 1
        WScript.Echo I + 1 & "> " & _
        updatesToInstall.Item(i).Title & _
        ": " & installationResult.GetUpdateResult(i).ResultCode         
    Next
'End If
Run Code Online (Sandbox Code Playgroud)

下一步是将它与不喜欢远程运行 VBScripts 的 psExec 结合在一起。我将以下批处理文件放在一起以将脚本本地复制到服务器,然后以系统用户身份运行 psExec 开始安装:

for /f %%i in (%1) do copy installUpdates.vbs \\%%i\c$
psexec @%1 -s cscript C:\installUpdates.vbs
Run Code Online (Sandbox Code Playgroud)

此时您所需要的只是向批处理脚本传递一个文本文件,其中包含您的计算机名称——每行一个,您就可以开始了。无需再登录每台服务器来启动 Windows 更新安装!

一个有点烦人的问题是,这是一个非常串行的执行,所以如果你有很多更新,它可能需要一段时间。除了分解您的机器列表并运行批处理文件的多个副本之外,我找不到解决此问题的好方法。不是世界末日。


一点点更新。我发现有一些安装,您只需要使用适当的权限以交互方式登录即可安装。基本上,如果 wsus 说它安装失败,你必须进入盒子。虽然这是一个很好的步骤,而不是必须登录到每个盒子。