Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- 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.
- The script is following locally run:
- cscript WUA_SearchDownloadInstall.vbs
- or remote via PsExec:
- "PsExec.exe \\RECHNERNAME -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
- 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.
- A quick and dirty solution is to incorporate these in a batch for a manageable number of clients:
- start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME1 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
- start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME2 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs"
- Here a CMD window now opens for each computer.
- If you want to still see the result you can command to a & break supplement:
- start c:\windows\system32\cmd /c "PsExec.exe \\PCNAME2 -u DOMAIN\USER -p PASSWORD -e cscript \\SERVER\SHARE\WUA_SearchDownloadInstall.vbs & pause"
- Tested under Windows XP 32 bit SP3, Windows 7 32 bit SP1, Windows Server 2008 32/64 bit including R2
- WUA_SearchDownloadInstall.vbs
- --------------------------------------------
- Set updateSession = CreateObject("Microsoft.Update.Session")
- Set updateSearcher = updateSession.CreateupdateSearcher()[/color]
- 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
- Else
- Set WSHShell = WScript.CreateObject("WScript.Shell")
- WScript.Echo "STOP Sophos AV..." & vbCRLF
- WshShell.Run "net stop SAVService", TRUE
- WshShell.Run "net stop 'Sophos AutoUpdate Service'", TRUE
- WScript.Sleep 10000
- End If
- WScript.Echo vbCRLF & "Creating collection of updates to download:"
- Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
- For I = 0 to searchResult.Updates.Count-1
- Set update = searchResult.Updates.Item(I)
- WScript.Echo I + 1 & "> adding: " & update.Title
- updatesToDownload.Add(update)
- Next
- WScript.Echo vbCRLF & "Downloading updates..."
- Set downloader = updateSession.CreateUpdateDownloader()
- downloader.Updates = updatesToDownload
- downloader.Download()
- WScript.Echo vbCRLF & "List of downloaded updates:"
- For I = 0 To searchResult.Updates.Count-1
- Set update = searchResult.Updates.Item(I)
- If update.IsDownloaded Then
- WScript.Echo I + 1 & "> " & update.Title
- End If
- Next
- 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 "Installing updates..."
- Set installer = updateSession.CreateUpdateInstaller()
- installer.Updates = updatesToInstall
- Set installationResult = installer.Install()
- 'Output results of install
- WScript.Echo "Installation Result: " & _
- installationResult.ResultCode
- 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
- If installationResult.RebootRequired = true Then
- WScript.Echo "" & vbCRLF
- WScript.Echo "System reboot now" & vbCRLF
- Set WSHShell = WScript.CreateObject("WScript.Shell")
- WshShell.Run "wuauclt /reportnow"
- WScript.Sleep 10000
- WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 10"
- Else
- WScript.Echo "" & vbCRLF
- WScript.Echo "No reboot needed" & vbCRLF
- Set WSHShell = WScript.CreateObject("WScript.Shell")
- WScript.Echo "START Sophos AV" & vbCRLF
- WshShell.Run "net start SAVService", TRUE
- WshShell.Run "net start 'Sophos AutoUpdate Service'", TRUE
- WshShell.Run "wuauclt /reportnow", TRUE
- End If
Add Comment
Please, Sign In to add comment