windows-server-2003 – 远程触发WSUS下载的更新安装

这一直困扰着我.我们的服务器设置为仅下载 Windows更新,以便在我们的双月补丁窗口中安装它们.在这段时间里,我在服务器上远程触发安装的方式看起来很高和很低,因此我不必登录到一百个或更多服务器并单击“立即安装更新”气球.

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

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

我将其修改如下,取出下载部分 – 因为我使用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

下一步是将它与psExec粘合在一起 – 这不喜欢远程运行VBScripts.我将以下批处理文件放在一起以将脚本本地复制到服务器,然后以作为系统用户运行的psExec启动安装:

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

此时您需要的只是将批处理脚本传递给一个文本文件,其中包含计算机的名称 – 每行一个,您就可以了.不再登录每个服务器以启动Windows更新安装!

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

一点点更新.我发现有些安装只需要以适当的安装权限进行交互式登录.基本上如果wsus说安装失败,你必须上机.虽然这是一个很好的步骤,从必须登录到每个框.

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...