Detecting and installing WSUS updates in Server 2008 Core
On a normal GUI-box, detecting or installing new updates after a fresh install is reasonably easy.
You just click the Updates Control panel item, or, for the more commandline orientated folks, run a wuauclt /detectnow and wait for the “There are new updates available” Systray icon to appear.
The problem with Server Core … there’s no way for you to see the “updates to install” notice in the system tray when you log on to the computer because, well, there’s no systray!
In comes a handy piece of VBscript that allows you to do a manual quick check and start off the installation process, using the in-box Windows Update Agent API.
http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx
Although the MSDN article states it does not run against SUS 1.0 servers, you don’t have to worry because both Windows Update (site) and WSUS 3.x employ the WUA API.
Save and run the script in the command prompt as “cscript
01 02 Set updateSession = CreateObject("Microsoft.Update.Session")03 Set updateSearcher = updateSession.CreateupdateSearcher()04 05 WScript.Echo "Searching for updates..." & vbCRLF06 07 Set searchResult = _08 updateSearcher.Search("IsInstalled=0 and Type='Software'")09 10 WScript.Echo "List of applicable items on the machine:"11 12 For I = 0 To searchResult.Updates.Count-113 Set update = searchResult.Updates.Item(I)14 WScript.Echo I + 1 & "> " & update.Title15 Next16 17 If searchResult.Updates.Count = 0 Then18 WScript.Echo "There are no applicable updates."19 WScript.Quit20 End If21 22 WScript.Echo vbCRLF & "Creating collection of updates to download:"23 24 Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")25 26 For I = 0 to searchResult.Updates.Count-127 Set update = searchResult.Updates.Item(I)28 WScript.Echo I + 1 & "> adding: " & update.Title29 updatesToDownload.Add(update)30 Next31 32 WScript.Echo vbCRLF & "Downloading updates..."33 34 Set downloader = updateSession.CreateUpdateDownloader()35 downloader.Updates = updatesToDownload36 downloader.Download()37 38 WScript.Echo vbCRLF & "List of downloaded updates:"39 40 For I = 0 To searchResult.Updates.Count-141 Set update = searchResult.Updates.Item(I)42 If update.IsDownloaded Then43 WScript.Echo I + 1 & "> " & update.Title44 End If45 Next46 47 Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")48 49 WScript.Echo vbCRLF & _50 "Creating collection of downloaded updates to install:"51 52 For I = 0 To searchResult.Updates.Count-153 set update = searchResult.Updates.Item(I)54 If update.IsDownloaded = true Then55 WScript.Echo I + 1 & "> adding: " & update.Title56 updatesToInstall.Add(update)57 End If58 Next59 60 WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)"61 strInput = WScript.StdIn.Readline62 WScript.Echo63 64 If (strInput = "N" or strInput = "n") Then65 WScript.Quit66 ElseIf (strInput = "Y" or strInput = "y") Then67 WScript.Echo "Installing updates..."68 Set installer = updateSession.CreateUpdateInstaller()69 installer.Updates = updatesToInstall70 Set installationResult = installer.Install()71 72 'Output results of install73 WScript.Echo "Installation Result: " & _74 installationResult.ResultCode75 WScript.Echo "Reboot Required: " & _76 installationResult.RebootRequired & vbCRLF77 WScript.Echo "Listing of updates installed " & _78 "and individual installation results:"79 80 For I = 0 to updatesToInstall.Count - 181 WScript.Echo I + 1 & "> " & _82 updatesToInstall.Item(i).Title & _83 ": " & installationResult.GetUpdateResult(i).ResultCode84 Next85 End If
- Comments Comments Off
