I've quickly modded our shutdown script to include wsus updates using a wsus script i got somewhere, and mangled them together - does this look ok before i trash everything ? (vbscript is not something i'm totally familiar with)
In theory this should load a .txt file with a list of certain groups of pc's and check for updates, install if neccesary then shutdown.
Code:Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys Dim sUser, sPassword 'set remote credentials sUser = "***********" sPassword = "***********" 'open list of client names Set oFSO = CreateObject("Scripting.FileSystemObject") Set oTS = oFSO.OpenTextFile("C:\Shutdown\test.txt") Do Until oTS.AtEndOfStream 'get next client name sClient = oTS.ReadLine 'get WMI locator Set oLocator = CreateObject("WbemScripting.SWbemLocator") 'Connect to remote WMI Set oConnection = oLocator.ConnectServer(sClient, _ "root\cimv2", sUser, sPassword) Set oWindows = oConnection.ExecQuery("Select " & _ "Name From Win32_OperatingSystem") For Each oSys In oWindows 'ShutdownOption = nForced_Power_Off 'Monthly log; dt = date() : nMonth = Year(dt)*1e2 + Month(dt) sLogFile = "C:\WUSforceupdate-" & nMonth & ".log" Set updateSession = CreateObject("Microsoft.Update.Session") Set updateSearcher = updateSession.CreateupdateSearcher() Set searchResult = _ updateSearcher.Search("IsInstalled=0 and Type='Software'") Set File = CreateObject("Scripting.FileSystemObject") Set LogFile = File.OpenTextFile(sLogFile, 8, True) LogFile.WriteLine("***************************************************************") LogFile.WriteLine( "START TIME : " & now) LogFile.WriteLine( "Searching for updates..." & vbCRLF) LogFile.WriteLine( "List of applicable items on the machine:") For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) LogFile.WriteLine( I + 1 & "> " & update.Title) Next Set WshShell = WScript.CreateObject("WScript.Shell") If searchResult.Updates.Count = 0 Then LogFile.WriteLine( "There are no applicable updates.") 'WshShell.popup "There are no applicable updates.",1 'ShutDown(ShutdownOption) '<-- O P T I O N A L 'Wscript.quit End If LogFile.WriteLine( vbCRLF & "Creating collection of updates to download:") Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl") For I = 0 to searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) LogFile.WriteLine( I + 1 & "> adding: " & update.Title ) updatesToDownload.Add(update) Next LogFile.WriteLine( vbCRLF & "Downloading updates...") Set downloader = updateSession.CreateUpdateDownloader() downloader.Updates = updatesToDownload downloader.Download() LogFile.WriteLine( vbCRLF & "List of downloaded updates:") For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) If update.IsDownloaded Then LogFile.WriteLine( I + 1 & "> " & update.Title ) End If Next Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl") LogFile.WriteLine( vbCRLF & _ "Creating collection of downloaded updates to install:" ) For I = 0 To searchResult.Updates.Count-1 set update = searchResult.Updates.Item(I) If update.IsDownloaded = true Then 'WshShell.popup "installing..." & vbNewLine & update.Title,1 LogFile.WriteLine( I + 1 & "> adding: " & update.Title ) updatesToInstall.Add(update) End If Next logFile.WriteLine( "Installing updates...") Set installer = updateSession.CreateUpdateInstaller() installer.Updates = updatesToInstall Set installationResult = installer.Install() 'Output results of install LogFile.WriteLine( "Installation Result: " & installationResult.ResultCode ) LogFile.WriteLine( "Reboot Required: " & installationResult.RebootRequired & vbCRLF ) LogFile.WriteLine( "Listing of updates installed " _ & "and individual installation results:" ) For I = 0 to updatesToInstall.Count - 1 LogFile.WriteLine( I + 1 & "> " & updatesToInstall.Item(i).Title _ & ": " & installationResult.GetUpdateResult(i).ResultCode ) Next If installationResult.RebootRequired = -1 Then LogFile.WriteLine( "RebootRequired") ' <-- normally now you should call for a R E B O O T..... End If 'ShutDown(ShutdownOption) '<-- O P T I O N A L LogFile.WriteLine( "STOP TIME : " & now) LogFile.WriteLine("***************************************************************") LogFile.Close 'wscript.echo "Updates are installed" oSys.Win32ShutDown(12) Next Loop 'close the text File oTS.Close


LinkBack URL
About LinkBacks



