-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcheckmissingOODupdates.vbs
More file actions
113 lines (100 loc) · 5 KB
/
Copy pathcheckmissingOODupdates.vbs
File metadata and controls
113 lines (100 loc) · 5 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
On Error Resume Next
version = "1.06"
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const ForWriting = 2
Const ForReading = 1
Const ForAppending = 8
Set autoUpdateClient = CreateObject("microsoft.Update.AutoUpdate")
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'")
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Set objADInfo = CreateObject("ADSystemInfo")
Set WshShell = WScript.CreateObject("WScript.Shell")
'Set WshSysEnv = WshShell.Environment("PROCESS")
Set ws = wscript.CreateObject("Scripting.FileSystemObject")
'Script Configuration----------------------------------------------------
'------------------------------------------------------------------------
scriptroot = "\\hou20017\batch$"
strDateStamp =Year(Now) & Right(100 + Month(Now), 2) & Right (100 + Day(Now), 2)
logfile = scriptroot & "\log\MissingSecAndCritUpdates" & strDateStamp & ".log"
strComputer1 = objADInfo.ComputerName
If strComputer = "" Then strComputer = wshShell.ExpandEnvironmentStrings("%Computername%")
If InStr(ucase(WScript.FullName),"CSCRIPT.EXE") Then blnCScript = TRUE Else blnCScript = False
OODList = scriptroot & "\log\OutOfDateSecAndCritUpdates" & strDateStamp & ".txt"
OODCompList = scriptroot & "\log\OutOfDateSecAndCritComputers" & strDateStamp & ".txt"
OODcheck = False
ComputerOOD = False
OODUpdates = 0
'End Script Configuration------------------------------------------------
'------------------------------------------------------------------------
Set l = ws.OpenTextFile (logfile, ForAppending, True)
Set OODfile = ws.OpenTextFile (OODList, ForAppending, True)
Set OODcompfile = ws.OpenTextFile (OODCompList, ForAppending, True)
If Err.Number <> 0 Then WriteLog(Err.Number & ": Description:" & Err.Description)
Err.Clear
autoUpdateClient.detectnow()
If searchResult.Updates.count = 0 Then
WriteLog("Up to date.")
Else
WriteLog("Missing " & searchResult.Updates.count & " updates.")
End If
'Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
objConnection.Open _
"Provider=SQLOLEDB;Data Source=houmwinetop01;" & _
"Trusted_Connection=Yes;Initial Catalog=SUSDB;"
For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
'strUpdates = strUpdates & update.Title
'objRecordSet.Open "SELECT UpdateId,CreationDate FROM PUBLIC_VIEWS.vUpdate where updateid='" & update.identity.updateid & "'", _
' objConnection, adOpenStatic, adLockOptimistic
strSQL = "Declare @updateid varchar(100);Set @updateid = '" & update.identity.updateid & "';" & _
"SELECT UpdateId,CreationDate,InstallationRebootBehavior FROM PUBLIC_VIEWS.vUpdate Where updateid = @updateid"
objRecordSet.Open strSQL, objConnection, adOpenStatic, adLockOptimistic
releasedate = objRecordSet.Fields("CreationDate").Value
rebootbehavior = objRecordSet.Fields("InstallationRebootBehavior").Value
On Error Goto 0
For counter = 0 To update.categories.count -1
If category = "" Then
category = update.categories.item(counter).name
Else
category = category & "; " & update.categories.item(counter).name
End If
checkcat = update.categories.item(counter).name
If checkcat = "Security Updates" Or checkcat = "Critical Updates" Then categorymatch = True
Next
If checkOOD(releasedate) And categorymatch Then
OODfile.WriteLine("[" & time & "] - " & strComputer & ",script version: " & version & "," & """Missing: " & update.Title & """, Update ID:" & update.identity.updateid & ", Release Date:" & releasedate & ", Reboot Behavior:" & rebootbehavior)
OODupdates = OODupdates +1
End If
If checkOOD(releasedate) And categorymatch Then ComputerOOD = True
WriteLog("""Missing: " & update.Title & """, Update ID:" & update.identity.updateid & ", Release Date:" & releasedate & ", Reboot Behavior:" & rebootbehavior)
If Not update.EulaAccepted Then update.AcceptEula
objRecordset.Close
category = ""
categorymatch = False
Next
If ComputerOOD Then OODfile.WriteLine("[" & time & "] - " & strComputer & ",script version: " & version & "," & "This computer has " & OODupdates & " updates out of date.")
If ComputerOOD Then OODcompfile.WriteLine(strComputer & ",""" & OODupdates & " updates out of date.""") Else OODcompfile.WriteLine(strComputer & ","" Up to date.""")
objConnection.Close
Set autoUpdateClient = Nothing
Set updateSession = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objADInfo = Nothing
Function WriteLog(strMsg)
l.writeline "[" & time & "] - " & strComputer & ",script version: " & version & "," & strMsg
' Output to screen if cscript.exe
If blnCScript Then WScript.Echo "[" & time & "] " & strMsg
End Function
Function checkOOD(releasedate)
d = CDate(releasedate)
date0 = DateAdd("m",-3,Now)
If d < date0 Then
checkOOD = True
Else
checkOOD = False
End If
End Function