Greg Shields Very useful web site: Navigate to http://www.microsoft.com/technet/community/columns/scripts/default.mspx and search for the July, 2005 issue of the Scripting Guys Newsletter “Tales from the Script”. This issue gives some good, but basic scripts you can use. We ’ll expand on those scripts shortly – and add to them the ability to use them on remote machines! There are a number of objects that can be created on the client, but only a few that can be interfaced through VBScript. Below is the mapping between the objects you can interface in VBScript and their associated COM object: Microsoft.Update.AgentInfo iWindowsUpdateAgentInfo Microsoft.Update.AutoUpdate iAutomaticUpdates Microsoft.Update.Downloader iUpdateDownloader Microsoft.Update.Installer iUpdateInstaller Microsoft.Update.Searcher iUpdateSearcher Microsoft.Update.ServiceManager iUpdateServiceManager Microsoft.Update.Session iUpdateSession Microsoft.Update.StringColl iStringCollection Microsoft.Update.SystemInfo iSystemInformation Microsoft.Update.UpdateColl iUpdateCollection Microsoft.Update.WebProxy iWebProxy Information about all of these can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wua_sdk/wua/interfaces.asp
Greg Shields '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_wsus-install-client.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: This script installs the WUA client and its necessary pre-requisites ' onto a list of computers and reboots the computer. The individual ' pre-requisites noted below must be in the same folder as where the script is run. ' ' INPUTS: A filename of a text file that includes the computers you want ' to scan. One computer per line. ' ' OUTPUTS: None ' ' SYNTAX: techmentor_wsus-install-client.vbs computers.txt ' '==========================================================================
Greg Shields strComputerList = WScript.Arguments.Item(0) strPreReq = &quot;Windows2000-KB842773-x86-ENU.EXE&quot; strPreReq2 = &quot;WindowsInstaller-KB893803-v2-x86.exe&quot; strAgent = &quot;WindowsUpdateAgent20-x86.exe&quot; Set objShell = CreateObject(&quot;WScript.Shell&quot;) Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set f = fso.OpenTextFile(strComputerList, 1, True) Do While f.AtEndOfLine <> True strComputer = f.ReadLine objShell.Run(&quot;psexec.exe \\\\&quot; & strComputer & &quot; -c &quot; & strPreReq & &quot; /quiet /norestart&quot;), 0, True objShell.Run(&quot;psexec.exe \\\\&quot; & strComputer & &quot; -c &quot; & strPreReq2 & &quot; /quiet /norestart&quot;), 0, True objShell.Run(&quot;psexec.exe \\\\&quot; & strComputer & &quot; -c &quot; & strAgent & &quot; /wuforce /quiet&quot;), 0, True Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\\\&quot; & strComputer & &quot;\\root\\cimv2&quot;) Set colOperatingSystems = objWMIService.ExecQuery(&quot;Select * from Win32_OperatingSystem&quot;) For Each objOperatingSystem in colOperatingSystems objOperatingSystem.Reboot() Next Loop WScript.Echo &quot;Done!&quot;
Greg Shields '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_wsus-detectinstalled.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: This script leverages the WUA client to identify the updates ' currently installed on a list of computers. ' ' INPUTS: A filename of a text file that includes the computers you want ' to scan. One computer per line. ' ' OUTPUTS: A .CSV file that includes each computer and the currently installed ' updates on that computer. ' ' SYNTAX: techmentor_wsus_detectinstalled.vbs computers.txt ' '==========================================================================
Greg Shields strComputerList = WScript.Arguments.Item(0) Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set f = fso.OpenTextFile(strComputerList, 1, True) Set objTextFile = fso.OpenTextFile(&quot;OUTPUT.csv&quot;, 2, True) objTextFile.WriteLine(&quot;Computer Name,Update Title&quot;) Do While f.AtEndOfLine <> True strComputer = f.ReadLine Set objSession = CreateObject(&quot;Microsoft.Update.Session&quot;, strComputer) Set objSearcher = objSession.CreateUpdateSearcher() intHistoryCount = objSearcher.GetTotalHistoryCount Set colHistory = objSearcher.QueryHistory(0, intHistoryCount) For Each objHistory in colHistory objTextFile.WriteLine(strComputer & &quot;,&quot; & Replace(objHistory.Title, &quot;,&quot;, &quot;&quot;)) Next Loop WScript.Echo &quot;Done!&quot;
Greg Shields '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_wsus-detectNotInstalled.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: This script leverages the WUA client to identify the updates ' not installed on a list of computers. ' ' INPUTS: A filename of a text file that includes the computers you want ' to scan. One computer per line. ' ' OUTPUTS: A .CSV file that includes each computer and the currently ' uninstalled updates on that computer. ' ' SYNTAX: techmentor_wsus_detectNotInstalled.vbs computers.txt ' '==========================================================================
Greg Shields strComputerList = WScript.Arguments.Item(0) Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set f = fso.OpenTextFile(strComputerList, 1, True) Set objTextFile = fso.OpenTextFile(&quot;OUTPUT.csv&quot;, 2, True) objTextFile.WriteLine(&quot;Computer Name,Update Title&quot;) Do While f.AtEndOfLine <> True strComputer = f.ReadLine Set objSession = CreateObject(&quot;Microsoft.Update.Session&quot;, strComputer) Set objSearcher = objSession.CreateUpdateSearcher() Set objResults = objSearcher.Search(&quot;Type='Software'&quot;) Set colUpdates = objResults.Updates For i = 0 to colUpdates.Count - 1 If colUpdates.Item(i).IsInstalled = FALSE Then objTextFile.WriteLine(strComputer & &quot;,&quot; & colUpdates.Item(i).Title) End If Next Loop WScript.Echo &quot;Done!&quot;
Greg Shields '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_wsus-install.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: This script leverages PSExec to remotely launch the 'install agent' ' on a list of remote computers. ' ' INPUTS: A filename of a text file that includes the computers you want ' to scan. One computer per line. Also, the username and password ' of the administrator in &quot;domain\\username&quot; format ' ' OUTPUTS: None ' ' SYNTAX: wsus-install.vbs computers.txt domain\\username PassWord! ' '==========================================================================
Greg Shields strComputerList = WScript.Arguments.Item(0) strUserName = WScript.Arguments.Item(1) strPassword = WScript.Arguments.Item(2) strAgent = &quot;techmentor_wsus-install-agent.vbs&quot; Set objShell = CreateObject(&quot;WScript.Shell&quot;) Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set f = fso.OpenTextFile(strComputerList, 1, True) Do While f.AtEndOfLine <> True strComputer = f.ReadLine fso.CopyFile strAgent, &quot;\\\\&quot; & strComputer & &quot;\\admin$\\system32\\&quot;, True WScript.Echo (&quot;psexec.exe \\\\&quot; & strComputer & &quot; -u &quot; & strUserName & &quot; -p &quot; & strPassword & &quot; &quot; & strAgent) Set objExecObject = objShell.Exec(&quot;psexec.exe \\\\&quot; & strComputer & &quot; -u &quot; & strUserName & &quot; -p &quot; & strPassword & &quot; cscript &quot; & strAgent) Loop WScript.Echo &quot;Done! “ '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_wsus-Install-agent.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: This script is the agent that actually downloads and installs the ' individual updates on each computer. This script leverages WUA to ' determine the necessary updates, install them, and reboot. A ' wuauclt /detectnow may be needed for the machine to upload its status ' back to the WSUS server. This script can either be run directly on ' a machine console or can be remotely run via techmentor_wsus-install.vbs. ' ' INPUTS: A filename of a text file that includes the computers you want ' to scan. One computer per line. ' ' OUTPUTS: None ' '========================================================================== Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set objAutomaticUpdates = CreateObject(&quot;Microsoft.Update.AutoUpdate&quot;) objAutomaticUpdates.EnableService objAutomaticUpdates.DetectNow Set objSession = CreateObject(&quot;Microsoft.Update.Session&quot;) Set objSearcher = objSession.CreateUpdateSearcher() Set objResults = objSearcher.Search(&quot;IsInstalled=0 and Type='Software'&quot;) Set colUpdates = objResults.Updates
Greg Shields Set objUpdatesToDownload = CreateObject(&quot;Microsoft.Update.UpdateColl&quot;) 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(&quot;Microsoft.Update.SystemInfo&quot;) If objSysInfo.RebootRequired Then Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\\\localhost\\root\\cimv2&quot;) Set colOperatingSystems = objWMIService.ExecQuery(&quot;Select * from Win32_OperatingSystem&quot;) For Each objOperatingSystem in colOperatingSystems objOperatingSystem.Reboot() Next End If End If
Greg Shields '========================================================================== ' ' VBScript Source File ' ' NAME: techmentor_WSUS-QtoMSMatch.vbs ' ' WARNING: This script is provided as-is with no implied or expressed ' warranties or guarantees of functionality. Use at your own risk. ' This script could lead to system problems or a system crash and ' the author of this script is not responsible or liable for any problems ' or errors associated with its use. Use of this script constitutes ' agreement with this warning. ' ' NOTE: For this script to function when not run on the WSUS server, you will ' need to enable TCP/IP and/or Named Pipes connections. Configuring the ' WSUS server for mixed mode authentication may also be likely. ' ' INPUTS: None ' ' OUTPUTS: A .CSV file with the update title matched with the MS number. ' '==========================================================================
Greg Shields strWSUSServer = “<Enter WSUS Server here>&quot; Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set objTextFile = fso.OpenTextFile(&quot;OUTPUT.csv&quot;, 2, True) objTextFile.WriteLine(&quot;MS Number,Q Number&quot;) Set conn = CreateObject(&quot;ADODB.Connection&quot;) Set rs = CreateObject(&quot;ADODB.Recordset&quot;) dbconn = &quot;Driver={SQL Server};Server=&quot; & strWSUSServer & &quot;;Database=SUSDB&quot; conn.open dbconn strSQLQuery = &quot;SELECT dbo.tbSecurityBulletinForRevision.SecurityBulletinID, dbo.tbLocalizedProperty.Title FROM dbo.tbLocalizedPropertyForRevision INNER JOIN dbo.tbLocalizedProperty ON dbo.tbLocalizedPropertyForRevision.LocalizedPropertyID = dbo.tbLocalizedProperty.LocalizedPropertyID INNER JOIN dbo.tbSecurityBulletinForRevision ON dbo.tbLocalizedPropertyForRevision.RevisionID = dbo.tbSecurityBulletinForRevision.RevisionID WHERE (dbo.tbLocalizedPropertyForRevision.LanguageID = 1033) ORDER BY dbo.tbSecurityBulletinForRevision.SecurityBulletinID&quot; rs.Open strSQLQuery, conn, 3, 3 While Not rs.EOF objTextFile.WriteLine(rs.Fields(0).Value & &quot;,&quot; & Replace(rs.Fields(1).Value, &quot;,&quot;, &quot;&quot;)) rs.MoveNext Wend WScript.Echo &quot;Done!&quot;