Windows Software Update Script (WSUS) Client VBScript
‘this script from the console of a computer that’s configured to obtain
‘updates from a WSUS server. It will contact the WSUS server, download
‘and install any approved updates, and then reboot.
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
WSUS wsus vbscriptWSUS wsus vbscript
1 Comment »
Filed under: WSUS

