Hacking WSUS #4 of 5 -- The "Big Red Button" or How to Patch When you want with WSUS
Most Windows administrators' biggest complaint about WSUS is its lack of an ability to patch on-demand, without having to wait for the Group Policy-scheduled time to arrive. Even in talking with the WSUS team, they have told me that they haven't planned for this capability natively in the WSUS 3.0 GUI.
However, within the scripting exposure, there is the capability to create a "YOU PATCH NOW!" script that will instruct a machine to scan itself, download any necessary patches, install them, and reboot if necessary. Since, according to Microsoft, this functionality is still not available when WSUS 3.0 arrives, keep this script close at hand. It will come in handy -- especially for patching servers!
As with some of our other scripts, you'll need to create a text file with a list of computer names -- one per line -- and reference that file when you run the script. An example: youPatchNOW.vbs computers.txt.
Click the link below for the code:
Set fso = CreateObject("Scripting.FileSystemObject")
Set objAutomaticUpdates = CreateObject("Microsoft.Update.AutoUpdate")
objAutomaticUpdates.EnableService
objAutomaticUpdates.DetectNow
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher()
Set objResults = objSearcher.Search("IsInstalled=0 and Type='Software'")
Set colUpdates = objResults.Updates
Set objUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
intUpdateCount = 0
For i = 0 to colUpdates.Count - 1
intUpdateCount = intUpdateCount + 1
Set objUpdate = colUpdates.Item(i)
objUpdatesToDownload.Add(objUpdate)
Next
If intUpdateCount = 0 Then
WScript.Quit
Else
Set objDownloader = objSession.CreateUpdateDownloader()
objDownloader.Updates = objUpdatesToDownload
objDownloader.Download()
Set objInstaller = objSession.CreateUpdateInstaller()
objInstaller.Updates = objUpdatesToDownload
Set installationResult = objInstaller.Install()
Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
If objSysInfo.RebootRequired Then
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\localhost\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
End If
End If