Wednesday, October 24, 2018

SCCM - Windows Update Agent Compliance Item

This is a script I created to pro-actively detect systems that failed to add the WSUS server settings.

I set the threshold high due to the initial client install will have errors until the client applies the settings.

Most of the time, the fix was to delete the c:\windows\system32\GroupPolicy\Machine\Registry.pol and re-run the actions.

Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "Failed to Add Update Source for WUAgent"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Windows\CCM\Logs\WUAHandler.log", ForReading)

i =0 

Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString)
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches

i = i + 1
        Next
    End If
Loop

'Wscript.Echo "Number of failures: " & i

If i > 20 then 
Wscript.quit(1)
End If

objFile.Close