加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

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

发布时间:2020-12-25 03:02:22 所属栏目:Windows 来源:网络整理
导读:这一直困扰着我.我们的服务器设置为仅下载 Windows更新,以便在我们的双月补丁窗口中安装它们.在这段时间里,我在服务器上远程触发安装的方式看起来很高和很低,因此我不必登录到一百个或更多服务器并单击“立即安装更新”气球. 有人知道远程触发更新安装的方

这一直困扰着我.我们的服务器设置为仅下载 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 %%ic$
psexec @%1 -s cscript C:installUpdates.vbs

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

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

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

(编辑:源码门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!