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:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
|
'VARIABLE DECLARATIONS
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
'On Error Resume Next
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("WScript.Shell")
Dim objLog : Set objLog = objFSO.CreateTextFile("C:\ServerLogs.txt")
Dim txtFile, arrServerList, Server, os, sp
'VARIABLE ASSIGNMENTS
txtFile = "C:\Servers.txt"
arrServerList=Split(objFSO.OpenTextFile(txtFile).ReadAll,vbNewLine)
'ATTAIN EACH SERVER THAT NEEDS SNMP AND DISKPERF
'AND CREATE THE UNATTENDED SETUP FILE FOR SNMP
For Each Server in arrServerList
Dim uaFile : Set uaFile = objFSO.CreateTextFile("\\" & Server & "\c$\snmp.ua",True)
uaFile.Writeline "[NetOptionalComponents]"
uaFile.Writeline "SNMP = 1"
uaFile.Close
'CALL TO THE FUNCTION AND SUBROUTINES TO DETERMINE THE OS,
'EDIT THE REGISTRY, RUN DISKPERF, AND INSTALL SNMP
os = determineOperatingSystem(server)
sp = determineServicePack(server)
WScript.Echo ("Will add SNMP files for " & os & " with service pack " & sp)
EditServerRegistry Server, os, sp
RunRmtProcess Server,"snmp"
RunRmtProcess Server,"diskperf"
objLog.WriteLine "=============================="
Next
'CLEAN UP OBJECTS AND CLOSE WSCRIPT
objLog.Close
Set objLog = Nothing
Set objShell = Nothing
Set objFSO = Nothing
wscript.echo ("The script is complete. Check C:\ServerLogs.txt for results")
wscript.quit
'******FUNCTION AND SUBROUTINES******
Function determineOperatingSystem(server)
'DECLARE VARIABLES
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
Dim objOperatingSystem
'GET OPERATING SYSTEM
For Each objOperatingSystem in colOperatingSystems
determineOperatingSystem = objOperatingSystem.Caption
Next
End Function
Function determineServicePack(server)
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & server & "\root\cimv2")
Dim colOperatingSystems : Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
Dim objOperatingSystem
'GET OPERATING SYSTEM SERVICE PACK VERSION
For Each objOperatingSystem in colOperatingSystems
determineServicePack = objOperatingSystem.ServicePackMajorVersion
Next
End Function
Sub editServerRegistry(srv,serverOS,spVer)
'DECLARE VARIABLES
Dim oldRegVal1,oldRegVal2, oldRegVal3, i386Location
Dim objRegistry
'DETERMINE WHERE THE PROPER i386 FOLDER IS
Select Case serverOS
Case "Microsoft Windows 2000 Server"
If spVer = 3 Then
i386Location = "\\\path"
ElseIf spVer = 4 Then
i386Location = "\\\path"
Else
WScript.Echo("Service pack level is not at 3 or 4. This script will now close!")
WScript.Quit
End If
Case "Microsoft(R) Windows(R) Server 2003, Standard Edition"
If spVer = 1 Then
i386Location = "\\\path"
ElseIf spVer = 2 Then
i386Location = "\\\path"
Else
WScript.Echo("Service pack level is not at 1 or 2. This script will now close!")
WScript.Quit
End If
Case Else
WScript.Echo ("Operating System is not Windows 2000 Server or Server 2003 Standard Edition. This script will now close!")
WScript.Quit
End Select
'GET CURRENT REGISTRY VALUES SO THEY MAY BE SAVED
Set objRegistry=GetObject("winmgmts:\\" & srv & "\root\default:StdRegProv")
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",oldRegVal1
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",oldRegVal2
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",oldRegVal3
'CHANGE THESE REGISTRY VALUES SO THAT WINDOWS KNOWS WHERE TO LOOK
'FOR THE FILES NEEDED FOR SNMP INSTALLATION. ALSO CREATES A NEW
'REGISTRY VALUE TO RETAIN THE PREVIOUS CONTENTS. THIS NEW VALUE
'IS NAMED THE SAME AS THE PREVIOUS AND IT'S APPENDED WITH .OLD
If oldRegVal1 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","SourcePath.old",oldRegVal1
End If
If oldRegVal2 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup","ServicePackSourcePath.old",oldRegVal2
End If
If oldRegVal3 <> i386Location Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath",i386Location
objRegistry.SetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","SourcePath.old",oldRegVal3
End If
End Sub
Sub RunRmtProcess(srv,process)
'VARIABLE DECLARATIONS
Dim strData, strResults
'SNMP INSTALLATION
If process="snmp" Then
strData = "c:\pstools\psexec \\" & srv & " -s -i -d sysocmgr /i:%windir%\inf\sysoc.inf /u:c:\snmp.ua /x /q /r"
End If
'DISKPERF -Y
If process="diskperf" Then
strData = "c:\pstools\psexec \\" & srv & " diskperf -y"
End If
'EXECUTES AND LOGS THE INSTALLATION PROCESS
Dim objExec : Set objExec=objShell.Exec(strData)
strResults=objExec.StdOut.ReadAll
With objLog
.WriteLine "Results for " & process & " install on " & srv & ":"
.WriteLine strResults
.WriteLine
End With
Set objExec = Nothing
End Sub
|