-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_windows_updates.wsf
More file actions
148 lines (128 loc) · 4.02 KB
/
check_windows_updates.wsf
File metadata and controls
148 lines (128 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<job>
<runtime>
<description>
Name:
check_windows_updates (nrpe_nt-plugin) 1.5 based on check_msupdates (nrpe_nt-plugin) 1.0
License:
The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute
copies of the plugins under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
Changelog / Contributors:
2009 May - Albrecht Dress (albrecht.dress@arcor.de)
2007 June - Micha Jankowski (fooky@pjwstk.edu.pl)
</description>
<named
name="h"
helpstring="Help"
type="simple"
required="false"
/>
<named
name="w"
helpstring="number of updates before warning status"
type="string"
required="false"
/>
<named
name="c"
helpstring="number of updates before critical status "
type="string"
required="false"
/>
</runtime>
<script language="VBScript">
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Const's and Var's
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Cons for return val's
Const intOK = 0
Const intWarning = 1
Const intCritical = 2
Const intUnknown = 3
' Cons for FSO
Const ForReading = 1
Const ForWriting = 2
Dim updatesNames
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Params
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Wscript.Arguments.Named.Exists("h") Then
Wscript.Echo "Usage: check_windows_updates.wsf /w:1 /c:2"
Wscript.Echo "/w: - number of updates before warning status "
Wscript.Echo "/c: - number of updates before critical status "
End If
If Wscript.Arguments.Named.Exists("w") Then
intWarningLvl = Cint(Wscript.Arguments.Named("w"))
Else
intWarningLvl = 0
End If
If Wscript.Arguments.Named.Exists("c") Then
intCriticLvl = Cint(Wscript.Arguments.Named("c"))
Else
intCriticLvl = 0
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
intResultDetect = objAutoUpdate.DetectNow
If intResultDetect = 0 Then
Else
WScript.Echo "WARNING: Unable to detect Automatic Updates."
Wscript.Quit(intUnknown)
End If
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher
intImportant = 0
intOptional = 0
Set objSysInfo = CreateObject("Microsoft.Update.SystemInfo")
If objSysInfo.RebootRequired Then
Wscript.Echo "Reboot required."
Wscript.Quit(intWarning)
End If
Set result = objSearcher.Search("IsInstalled = 0 and IsHidden = 0")
Set colDownloads = result.Updates
For Each objEntry in colDownloads
if objEntry.AutoSelectOnWebSites Then
if intImportant = 0 Then
importantNames = objEntry.Title
else
importantNames = importantNames & "; " & objEntry.Title
End If
intImportant = intImportant + 1
Else
If intOptional = 0 Then
optionalNames = objEntry.Title
Else
optionalNames = optionalNames & "; " & objEntry.Title
End If
intOptional = intOptional + 1
End If
Next
If intImportant + intOptional > 0 Then
echoStr = "Updates: " & intImportant & " important, " & intOptional & " optional|"
If intImportant > 0 Then
echoStr = echoStr & "Important: " & importantNames
If intOptional > 0 Then
echoStr = echoStr & " (note: optional updates not listed)"
End If
Else
echoStr = echoStr & "Optional: " & optionalNames
End If
WScript.Echo echoStr
If intImportant > intCriticLvl Then
Wscript.Quit(intCritical)
End If
If intImportant > intWarningLvl Then
Wscript.Quit(intWarning)
End If
Wscript.Quit(intOK)
Else
WScript.Echo "No updates waiting or installing."
Wscript.Quit(intOK)
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
</script>
</job>