Install Microsoft and Windows Updates

Table of Contents

A lot of scripts out there only install windows updates, this one gets the lot.
I’ve found that there are a number of patches not included in the LanGuard patch management, so here’s a script to fill in the gaps.

This script is a modified version of the one found here – blogs.technet.com/b/chrad/archive/2009/07/13/dynamic-provisioning-with-vmm-proxy-windows-updates-and-scripts.aspx

Also just added the ability to skip updates.
So if you don’t want the bing bar or windows search or any other update, just put add the name to the array. (Should also work with Most KB Numbers)

Const ssDefault = 0
 Const ssManagedServer = 1 
 Const ssOthers = 3 'Microsoft Updates
 Const ssWindowsUpdate = 2 'Windows Updates
 'Array of updates to skip. 
 SkipUpdates = Array("bing","windows live","windows search")
 '#############################
 ' Create Session
 '#############################
 Set UpdateSession = CreateObject("Microsoft.Update.Session")
 Set UpdateSearcher = UpdateSession.CreateUpdateSearcher()
 '#############################
 ' Register Microsoft Update
 '#############################
 RegisterMu
 updateSearcher.ServerSelection = ssOthers ' 0 Then
 bSkip = True
 Exit For
 End if
 Next
 If bSkip = True Then
 WScript.Echo "Skipping update " & update.Title
 Else
 'WScript.Echo "[" & strSpacer & I & "]  Found Update, Marking For Download:  " & update.Title
 UpdatesToDownload.Add(Update)
 End if 
     
 Next
 '#############################
 ' Download Updates
 '#############################
 Set Downloader = UpdateSession.CreateUpdateDownloader()
 Downloader.Updates = UpdatesToDownload
 On Error Resume Next
 Downloader.Download()
 If Err.number  0 Then
     Wscript.Echo "An error occurred in  Downloader.Download() of updates"
     Wscript.Echo "Number: " & err.number
     Wscript.Echo "Description:  " & err.Description
     Wscript.Quit (Err.number)
 End If
 On Error Goto 0
 '#############################
 ' Create List of Updates to Install
 '#############################
 Set UpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
 For I = 0 To SearchResult.Updates.Count-1
     set Update = SearchResult.Updates.Item(I)
     If Update.IsDownloaded = true Then
         UpdatesToInstall.Add(Update)
     End If
 Next
 '#############################
 ' Install Updates
 '#############################
 Set Installer = UpdateSession.CreateUpdateInstaller()
 Installer.Updates = UpdatesToInstall
 Set InstallationResult = Installer.Install()
 wscript.Echo "Installation Result: " & InstallationResult.ResultCode
 wscript.Echo "Reboot Required: " & InstallationResult.RebootRequired
 wscript.Echo "Listing of updates installed and individual installation results:"
     
     For I = 0 to UpdatesToInstall.Count - 1
         WScript.Echo I + 1 & "> " & Chr(9) & UpdatesToInstall.Item(I).Title & Chr(9) & ": " & TranslateMuCode(InstallationResult.GetUpdateResult(i).ResultCode)
     Next
 '#############################
 ' Quit
 '#############################
 WScript.Quit
 '================================================================================
 ' Translate Microsoft Update Installation Results
 '================================================================================
 Function TranslateMuCode(theCode)
   TranslateMuCode = "[" & theCode & "] "
   if (theCode = 0) Then TranslateMuCode = TranslateMuCode & "Not Started"
   if (theCode = 1) Then TranslateMuCode = TranslateMuCode & "In Progress"
   if (theCode = 2) Then TranslateMuCode = TranslateMuCode & "Succeeded"
   if (theCode = 3) Then TranslateMuCode = TranslateMuCode & "Succeeded with Errors"
   if (theCode = 4) Then TranslateMuCode = TranslateMuCode & "Failed"
   if (theCode = 5) Then TranslateMuCode = TranslateMuCode & "Aborted"
 End Function
 '================================================================================
 ' Register Microsoft Update (if never registered)
 '================================================================================
 Function RegisterMu
     Dim fso
     Dim file
     Dim WshShell
     Dim updateService
     Dim updateServiceManager
     
     found = false
     
     Set fso = CreateObject("Scripting.FileSystemObject")    
     Set WshShell = WScript.CreateObject ("WScript.Shell")
     
     Set updateServiceManager = CreateObject("Microsoft.Update.ServiceManager")
     Set updateService = updateServiceManager.Services
     
     If err  0 Then
         WScript.Echo "CreateObject(Microsoft.Update.ServiceManager) failed with error 0x" & Hex(err.Number)  & err.Description
         WScript.Quit(2)
     End If
     For I=0 to updateService.Count - 1
         Set item = updateService.Item(i)
         If item.ServiceID = "7971f918-a847-4430-9279-4a52d1efe18d" Then
             found = true
         End IF
     Next    
       
     IF found = false Then
         updateServiceManager.AddService2 "7971f918-a847-4430-9279-4a52d1efe18d", 2, ""
         
         If err  0 Then
             WScript.Echo "updateServiceManager.AddService() failed with error 0x" & Hex(err.Number) & err.Description
         Else
             WScript.Echo "MU is registered with WU Agent"
         End IF
     End IF
 END Function
 

Our Services