Windows Update Reset - Has anyone created a package?
Some of our machines are getting errors when checking for updates. Microsoft recommends the rather lengthy procedure in the URL below. I'm hoping someone here has already created a PDQ package for this so I will save a lot of time and testing and debugging.
Anyone?
The URL:
https://support.microsoft.com/en-us/help/971058/how-do-i-reset-windows-update-components
0
Comments
Thank you! I'll give it a try!
This is what I use. Stops WUAU, Resets the AU settings, clears the software distribution folder and adds our WSUS keys, restarts the AU and the set off an update check.
It then reports back if machines need more updates or not to a set of folders on a specified server. I used VBSEdit to roll it up into an EXE and it works every time.
Built from a few other scripts from other sources, so I can't take credit, but give it a whirl and see what you think.
-------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
Dim WshNetwork,updateSession,updateSearcher,searchResult,installationResult,updatesToDownload,updatesToInstall,downloader,update,installer,objshell,ComputerName,objTextFile,File,Shell,Network,objNetwork,AppShell,objOutputFile,strComputer,objFSO,strServiceName,objWMIService,colListOfServices,objService
Dim i: i = 0
Set Shell = CreateObject("WScript.Shell")
Set Network = CreateObject("WScript.Network")
Set objNetwork = CreateObject("Wscript.Network")
Set AppShell = CreateObject("Shell.Application")
Set File = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
strServiceName = "wuauserv"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
ComputerName = WshNetwork.ComputerName
'Stopping Windows Update service
For Each objService in colListOfServices
objService.StopService()
Next
WScript.Sleep 1000
'Applying Windows Update settings
Shell.Run "regedit /s \\SERVERNAME\netlogon\TASKS\AUOnReg.reg"
WScript.Sleep 1000
'Delete SoftwareDistribution
dim wshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """\\bricht\pdq$\windowsupdate\DelSoftwareDistContents.bat"""
WScript.Sleep 1000
'Starting Windows Update service
For Each objService in colListOfServices
objService.StartService()
Next
WScript.Sleep 1000
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
If searchResult.Updates.Count = 0 Then
If (File.FileExists("\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt")) Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt", "\\Holst\WUlog$\2-Complete" & ComputerName & ".txt"
Else
Set objOutputFile = File.CreateTextFile("\\SERVERNAME\WUlog$\2-Complete\" & ComputerName & ".txt", True)
objOutputFile.WriteLine(123)
objOutputFile.Close
End If
WScript.Quit
End If
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For i = 0 To searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(i)
updatesToDownload.Add(update)
Next
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
For i = 0 To searchResult.Updates.Count - 1
Set update = searchResult.Updates.Item(i)
If update.IsDownloaded = True Then updatesToInstall.Add(update)
Next
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
If installationResult.RebootRequired Then
Set objOutputFile = File.CreateTextFile("\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt", True)
objOutputFile.WriteLine(123)
objOutputFile.Close
CreateObject("WScript.Shell").Run "shutdown.exe /r /t 0"
End If
Thank you Lee West. For everyone's information the first script submitted does not work for Windows 10. I updated the script based on article in the OP but it did not clear up the issue. I'd prefer not to use VB Script and am trying a pure batch solution. I'll report my results either way.