I asked this question at Stack Overflow but they said I would have better luck here. I am using VBScript to automate a lot of server tasks, I'm simply checking to make sure the server build team did their job before the server actually gets used.
One of my tasks I need to do is Check if there are any Critical Updates. It seems like this would be easy enough but I'm having A LOT of trouble with it. I am not familiar with WSUS, I've never dealt with it but I need to communicate with it.
Here is what I have in my vbscript for this type of logic
'Microsoft Magic
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsAssigned=1 and isHidden=0 and IsInstalled=0 and Type='Software'")
'End Microsoft Magic
If Err.Number <> 0 Then ' If errors
objResult.Text = "FAIL. Cannot connect to WSUS. Error: " & Err.Number
Err.Clear
Else ' No Errors'
If searchResult.Updates.Count <> 0 Then ' If Updates were found
For i = 0 to searchResult.Updates.Count - 1 'Just count the number of updates
count = count + 1
Next
objResult.Text = "FAIL. There are " & count & " updates that need to be installed"
Else
objResult.Text = "PASS. All updates are installed"
End If
If NOT len(objResult.Text) Then 'Just in case searchResult produces an error
objResult.Text = "FAIL. Could not query Windows Update Server"
End If
End If
The output gets sent to an XML file. Anyways, on my test server and on other servers I have tried it on (only two others). It seems to work fine and it passes. In production, I'm getting a lot of errors where I get
FAIL. Could not query Windows Update Server
So, what is happening is it won't connect to Windows Update -- The object "Microsoft.Update.Session" uses the windows update agent to manage whether the updates are being handled by windows update or a WSUS, but sometimes it just doesn't do it and I don't have an explanation or even what I can do.
I've been trying to resolve this a few days but it is hard for me to test it and see it failing, I just get a phonecall stating a server slated for production failed when it isn't suppose to be.
Any suggestions? I can provide more information for clarity if need be.