Check how many windows update are available for servers

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Check how many windows update are available for servers

Post by vindicta »

Hello,

I know there was a topic before to check for windows updates, but the active script in there was not working.
So that is why I try it again?

Does anyone has an script to check how many windows updates are available on al lot of windows 2008 - windows 2012 servers? I need to check these servers (all remote) and want a number in return.

I hope someone can help me with that.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I know there was a topic before to check for windows updates, but the active script in there was not working.
What exactly script you are using?
What exactly means "not working"? What error do you see?
Does anyone has an script to check how many windows updates are available on al lot of windows 2008 - windows 2012 servers? I need to check these servers (all remote) and want a number in return.
If you can use single admin account for all remote systems, try this script
(Shell Script test method, 1 parameter - target hostname)

Code: Select all

Option Explicit
const statusAlive       = "scriptRes:Host is alive:"
const statusDead        = "scriptRes:No answer:"
const statusUnknown     = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk          = "scriptRes:Ok:"
const statusBad         = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
dim updateSession, updateSearcher, searchResult

if objArgs.Count>1 then
 strComputer = objArgs(0) 

Set updateSession = CreateObject
("Microsoft.Update.Session",strComputer)
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
if searchResult.Updates.Count>0 then
  WScript.StdOut.Write statusBad & searchResult.Updates.Count & " updates found!"
else
  WScript.StdOut.Write statusOk & "No new updates found."
End If

else
 WScript.StdOut.WriteLine statusUnknown & "Not enough parameters specified" 
end if
Regards
Alex
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

Hi Alex,

Thank you for your fast respons.

I tried all the sripts in this thread:
http://www.ks-soft.net/cgi-bin/phpBB/vi ... ows+update

I have many servers in different vlan's with different admin accounts, but in every vlan is a domain controller upon which I have installed an r.m.a. agent.
So basically i can use the scipt you provided in this thread, because I can use
the r.m.a. agent needed for the specific server.

When I use your script, I get an unknown error.

This is my 'start cmd' cmd /c cscript /B /E:VBScript %Script% %Params%
then your script and in the field 'Params' I type in the name of the server. Even localhost or the IP-address gives me the unknown error.

Maybe I overlooked something?
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

Hi Alex,

This script seems to work:

Code: Select all

const statusAlive = "scriptRes:Host is alive:" 
const statusDead = "scriptRes:No answer:" 
const statusUnknown = "scriptRes:Unknown:" 
const statusNotResolved = "scriptRes:Unknown host:" 
const statusOk = "scriptRes:Ok:" 
const statusBad = "scriptRes:Bad:" 
const statusBadContents = "scriptRes:Bad contents:" 

' check this category for 'High Priority' updates 
category = "UpdateClassification" 
highpriority = ",Security Updates,Update Rollups,Critical Updates,Service Packs" 

' create instance of update.searcher (offline) 
Set objSearcher = CreateObject("Microsoft.Update.Searcher") 
objSearcher.Online = 1 

' find and fetch collection of updates 
Set objResults = objSearcher.Search("Type='Software' and IsInstalled=0") 
Set colUpdates = objResults.Updates 

count = 0 
titles = "" 
For i = 0 to colUpdates.Count - 1 
' check categories 
Set colCategories = colUpdates.Item(i).Categories 
For c = 0 to colCategories.Count - 1 
If colCategories.item(c).Type = category _ 
And InStr(highPriority, "," & colCategories.item(c).Name & ",") > 0 Then 
count = count + 1 
titles = titles & vbCRLF & colUpdates.Item(i).Title 
End If 
Next 
Next 

if count > 0 then 
WScript.StdOut.Write statusBad & colupdates.Updates.Count & " critical updates found!" 
else 
WScript.StdOut.Write statusOk 'No new critical updates found 
End If 




'If count > 0 Then 
'Wscript.Echo count & " pending updates:" & titles 
'Wscript.Quit 2 
'Else 
'Wscript.Echo "No pending updates" 
'Wscript.Quit 0 
'End If 
But then again, i cannot give in a servername.
And I see now that it gives me the 'OK' status..but i have Windows 2008 Service Pack 2 as important update not yet installed. And I see this in my Windows Update screen.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Added some error checking.
No parameters should be specified for local system.
Or one parameter - host name/IP of target system

Code: Select all

Option Explicit
On Error Resume Next
 
const statusAlive       = "scriptRes:Host is alive:"
const statusDead        = "scriptRes:No answer:"
const statusUnknown     = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk          = "scriptRes:Ok:"
const statusBad         = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
 
dim updateSession, updateSearcher, searchResult, objArgs

Set objArgs = WScript.Arguments
checkForError(1)

if objArgs.Count=0 Then
  Set updateSession = CreateObject("Microsoft.Update.Session")
else
  Set updateSession = CreateObject("Microsoft.Update.Session",objArgs(0))
end if
checkForError(2)

Set updateSearcher = updateSession.CreateupdateSearcher()
checkForError(3)
 
Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
checkForError(4)

if searchResult.Updates.Count>0 then
  WScript.StdOut.Write statusBad & searchResult.Updates.Count & " updates found!"
else
  WScript.StdOut.Write statusOk & "No new updates found."
End If

Sub checkForError(txt)
 If Err.Number <> 0 Then
      WScript.StdOut.Write statusUnknown & "(" & txt & ") " &Err.Description
      WScript.Quit
 End If
End Sub
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

Strange issue is happening:

When i use the scipt you just posted and test it like a normal test. I gives me the 'Bad' status reply.

When i test in the Shell Script screen i get this result:
[9:38:18 PM] HostMonitor is going to execute "WindowsUpdate -alex van forum" script ...
[9:38:26 PM] Script executed, correct result received:
----------
- Status: Bad
- Reply: 2 updates found!
----------

Also a kind of strange, because i see only 1 update ready in the windows update screen.
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

And when i use the Shell Script screen and test with an R.M.A agent and a parameter (the server name). I get this:

[9:53:25 PM] Agent: active-ade-amf-sbs001.-----.local is going to execute "WindowsUpdate -alex van forum" script ...
[9:53:35 PM] Agent error: no responce from agent within specified timeout

Even with a timeout of 600 sec.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

trange issue is happening:
When i use the scipt you just posted and test it like a normal test. I gives me the 'Bad' status reply.
When i test in the Shell Script screen i get this result:
"Shell Script screen" also returns Bad status (more than 0 updates found.)

You may show update name using searchResult.Updates.Item(0)
Script that shows last available Update may look like the following:
Option Explicit
On Error Resume Next

const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

dim updateSession, updateSearcher, searchResult, objArgs

Set objArgs = WScript.Arguments
checkForError(1)

if objArgs.Count=0 Then
Set updateSession = CreateObject("Microsoft.Update.Session")
else
Set updateSession = CreateObject("Microsoft.Update.Session",objArgs(0))
end if
checkForError(2)

Set updateSearcher = updateSession.CreateupdateSearcher()
checkForError(3)

Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
checkForError(4)

if searchResult.Updates.Count>0 then
WScript.StdOut.Write statusBad & searchResult.Updates.Count & " updates found. (last: " & searchResult.Updates.Item(searchResult.Updates.Count-1) & ")"
else
WScript.StdOut.Write statusOk & "No new updates found."
End If

Sub checkForError(txt)
If Err.Number <> 0 Then
WScript.StdOut.Write statusUnknown & "(" & txt & ") " &Err.Description
WScript.Quit
End If
End Sub
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

[9:53:25 PM] Agent: active-ade-amf-sbs001.-----.local is going to execute "WindowsUpdate -alex van forum" script ...
[9:53:35 PM] Agent error: no responce from agent within specified timeout Even with a timeout of 600 sec.
Try to start script manually on RMA system without "/B" command line switch

RMA started as service?
what account do you use to run agent?
UAC enabled?

Regards
Alex
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

That, gives me this answer:

[10:39:11 PM] Script executed, correct result received:
----------
- Status: Bad
- Reply: 2 updates found. (last: Microsoft .NET Framework 4 for Windows Server 2008 x64-based Systems (KB982671))
----------

But still in hostmonitor itself it only says: Bad. (not why, or how many).

And remote isn't working as I described.
Sorry to bother you with this..
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

KS-Soft wrote:
[9:53:25 PM] Agent: active-ade-amf-sbs001.-----.local is going to execute "WindowsUpdate -alex van forum" script ...
[9:53:35 PM] Agent error: no responce from agent within specified timeout Even with a timeout of 600 sec.
Try to start script manually on RMA system without "/B" command line switch
Doesn't work.

RMA started as service?
Yes
what account do you use to run agent?
New created domain-admin account.
UAC enabled?
User Access Control is disabled.

Regards
Alex
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Try to start script manually on RMA system without "/B" command line switch
Doesn't work.
What exactly means does not work? What exactly error message do you see?

Regards
Alex
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

- Status: Bad
- Reply: 2 updates found. (last: Microsoft .NET Framework 4 for Windows Server 2008 x64-based Systems (KB982671))
----------
But still in hostmonitor itself it only says: Bad. (not why, or how many).
----------
if searchResult.Updates.Count>0 then
WScript.StdOut.Write statusBad & searchResult.Updates.Count & " updates found. (last: " & searchResult.Updates.Item(searchResult.Updates.Count-1) & ")"
Don't see how this may happen :roll: only one command in script may return Bad status and this command returns searchResult.Updates.Count as well
Could you please send screen shots to support@ks-soft.net?

Regards
Alex
vindicta
Posts: 11
Joined: Thu Jan 02, 2014 4:42 am

Post by vindicta »

See your mail. The local-server is solved. I see now that there are 2 updates pending. And the name of the last.

But my remote servers still gives me a time-out when I try it via 'Lets Try' screen.
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

resume: script works, timeout was too short

Regards
Alex
Post Reply