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 ” since the default script host is graphical (wscript) on a Core box.
| 01 | |
| 02 | Set updateSession = CreateObject("Microsoft.Update.Session") |
| 03 | Set updateSearcher = updateSession.CreateupdateSearcher() |
| 04 | |
| 05 | WScript.Echo "Searching for updates..." & vbCRLF |
| 06 | |
| 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-1 |
| 13 | Set update = searchResult.Updates.Item(I) |
| 14 | WScript.Echo I + 1 & "> " & update.Title |
| 15 | Next |
| 16 | |
| 17 | If searchResult.Updates.Count = 0 Then |
| 18 | WScript.Echo "There are no applicable updates." |
| 19 | WScript.Quit |
| 20 | End If |
| 21 | |
| 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-1 |
| 27 | Set update = searchResult.Updates.Item(I) |
| 28 | WScript.Echo I + 1 & "> adding: " & update.Title |
| 29 | updatesToDownload.Add(update) |
| 30 | Next |
| 31 | |
| 32 | WScript.Echo vbCRLF & "Downloading updates..." |
| 33 | |
| 34 | Set downloader = updateSession.CreateUpdateDownloader() |
| 35 | downloader.Updates = updatesToDownload |
| 36 | downloader.Download() |
| 37 | |
| 38 | WScript.Echo vbCRLF & "List of downloaded updates:" |
| 39 | |
| 40 | For I = 0 To searchResult.Updates.Count-1 |
| 41 | Set update = searchResult.Updates.Item(I) |
| 42 | If update.IsDownloaded Then |
| 43 | WScript.Echo I + 1 & "> " & update.Title |
| 44 | End If |
| 45 | Next |
| 46 | |
| 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-1 |
| 53 | set update = searchResult.Updates.Item(I) |
| 54 | If update.IsDownloaded = true Then |
| 55 | WScript.Echo I + 1 & "> adding: " & update.Title |
| 56 | updatesToInstall.Add(update) |
| 57 | End If |
| 58 | Next |
| 59 | |
| 60 | WScript.Echo vbCRLF & "Would you like to install updates now? (Y/N)" |
| 61 | strInput = WScript.StdIn.Readline |
| 62 | WScript.Echo |
| 63 | |
| 64 | If (strInput = "N" or strInput = "n") Then |
| 65 | WScript.Quit |
| 66 | ElseIf (strInput = "Y" or strInput = "y") Then |
| 67 | WScript.Echo "Installing updates..." |
| 68 | Set installer = updateSession.CreateUpdateInstaller() |
| 69 | installer.Updates = updatesToInstall |
| 70 | Set installationResult = installer.Install() |
| 71 | |
| 72 | 'Output results of install |
| 73 | WScript.Echo "Installation Result: " & _ |
| 74 | installationResult.ResultCode |
| 75 | WScript.Echo "Reboot Required: " & _ |
| 76 | installationResult.RebootRequired & vbCRLF |
| 77 | WScript.Echo "Listing of updates installed " & _ |
| 78 | "and individual installation results:" |
| 79 | |
| 80 | For I = 0 to updatesToInstall.Count - 1 |
| 81 | WScript.Echo I + 1 & "> " & _ |
| 82 | updatesToInstall.Item(i).Title & _ |
| 83 | ": " & installationResult.GetUpdateResult(i).ResultCode |
| 84 | Next |
| 85 | End If |