opexxx

WUA_SearchDownloadInstall.vbs

May 3rd, 2014
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. This script triggers the WUA API, loads all required updates from the WSUS server to the client, and installs it. This also updates, which together should be installed, or those that build on each other are grouped together in groups. Also, the script detects whether a reboot is required and executes on demand also this.
  2.  
  3. We have the original script changed so that it, if it has found updates, solution stops our anti-virus (line 22-25 - that accelerated the update on our POS systems by factor of 10) and automatically performs the reboot without asking or the AV program starts again (line 98-100), if not a reboot will be needed.
  4.  
  5. The script is following locally run:
  6.  
  7. cscript WUA_SearchDownloadInstall.vbs
  8.  
  9. or remote via PsExec:
  10.  
  11. "PsExec.exe \\RECHNERNAME -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
  12.  
  13. Trigger multiple computers from a remote machine, you might be the @ file-use option of PsExec - unfortunately they are executed one at a time, which is much too time consuming.
  14.  
  15. A quick and dirty solution is to incorporate these in a batch for a manageable number of clients:
  16.  
  17. start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME1 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
  18. start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME2 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
  19.  
  20. Here a CMD window now opens for each computer.
  21.  
  22. If you want to still see the result you can command to a & break supplement:
  23.  
  24. start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME2 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs & pause"
  25.  
  26. Tested under Windows XP 32 bit SP3, Windows 7 32 bit SP1, Windows Server 2008 32/64 bit including R2
  27.  
  28.  
  29. WUA_SearchDownloadInstall.vbs
  30. --------------------------------------------
  31. Set updateSession = CreateObject("Microsoft.Update.Session")
  32. Set updateSearcher = updateSession.CreateupdateSearcher()[/color]
  33.  
  34. WScript.Echo "Searching for updates..." & vbCRLF
  35. Set searchResult = _
  36. updateSearcher.Search("IsInstalled=0 and Type='Software'")
  37.  
  38. WScript.Echo "List of applicable items on the machine:"
  39. For I = 0 To searchResult.Updates.Count-1
  40. Set update = searchResult.Updates.Item(I)
  41. WScript.Echo I + 1 & "> " & update.Title
  42. Next
  43. If searchResult.Updates.Count = 0 Then
  44. WScript.Echo "There are no applicable updates."
  45. WScript.Quit
  46. Else
  47. Set WSHShell = WScript.CreateObject("WScript.Shell")
  48. WScript.Echo "STOP Sophos AV..." & vbCRLF
  49. WshShell.Run "net stop SAVService", TRUE
  50. WshShell.Run "net stop 'Sophos AutoUpdate Service'", TRUE
  51. WScript.Sleep 10000
  52.  
  53. End If
  54.  
  55. WScript.Echo vbCRLF & "Creating collection of updates to download:"
  56. Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
  57. For I = 0 to searchResult.Updates.Count-1
  58. Set update = searchResult.Updates.Item(I)
  59. WScript.Echo I + 1 & "> adding: " & update.Title
  60. updatesToDownload.Add(update)
  61. Next
  62. WScript.Echo vbCRLF & "Downloading updates..."
  63. Set downloader = updateSession.CreateUpdateDownloader()
  64. downloader.Updates = updatesToDownload
  65. downloader.Download()
  66. WScript.Echo vbCRLF & "List of downloaded updates:"
  67. For I = 0 To searchResult.Updates.Count-1
  68. Set update = searchResult.Updates.Item(I)
  69. If update.IsDownloaded Then
  70. WScript.Echo I + 1 & "> " & update.Title
  71. End If
  72. Next
  73. Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
  74. WScript.Echo vbCRLF & _
  75. "Creating collection of downloaded updates to install:"
  76. For I = 0 To searchResult.Updates.Count-1
  77. set update = searchResult.Updates.Item(I)
  78. If update.IsDownloaded = true Then
  79. WScript.Echo I + 1 & "> adding: " & update.Title
  80. updatesToInstall.Add(update)
  81. End If
  82. Next
  83. WScript.Echo "Installing updates..."
  84. Set installer = updateSession.CreateUpdateInstaller()
  85. installer.Updates = updatesToInstall
  86. Set installationResult = installer.Install()
  87.  
  88. 'Output results of install
  89. WScript.Echo "Installation Result: " & _
  90. installationResult.ResultCode
  91. WScript.Echo "Reboot Required: " & _
  92. installationResult.RebootRequired & vbCRLF
  93. WScript.Echo "Listing of updates installed " & _
  94. "and individual installation results:"
  95.  
  96. For I = 0 to updatesToInstall.Count - 1
  97. WScript.Echo I + 1 & "> " & _
  98. updatesToInstall.Item(i).Title & _
  99. ": " & installationResult.GetUpdateResult(i).ResultCode
  100. Next
  101. If installationResult.RebootRequired = true Then
  102. WScript.Echo "" & vbCRLF
  103. WScript.Echo "System reboot now" & vbCRLF
  104. Set WSHShell = WScript.CreateObject("WScript.Shell")
  105. WshShell.Run "wuauclt /reportnow"
  106. WScript.Sleep 10000
  107. WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 10"
  108. Else
  109. WScript.Echo "" & vbCRLF
  110. WScript.Echo "No reboot needed" & vbCRLF
  111. Set WSHShell = WScript.CreateObject("WScript.Shell")
  112. WScript.Echo "START Sophos AV" & vbCRLF
  113. WshShell.Run "net start SAVService", TRUE
  114. WshShell.Run "net start 'Sophos AutoUpdate Service'", TRUE
  115. WshShell.Run "wuauclt /reportnow", TRUE
  116. End If
Add Comment
Please, Sign In to add comment