-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.vbs
214 lines (175 loc) · 14.2 KB
/
Inventory.vbs
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2012
'
' NAME: Manoj Ravikumar Nair
'
' AUTHOR: Microsoft Corp. , Microsoft IT
' DATE : 6/18/2013
'
' COMMENT:
'
'==========================================================================
on Error Resume Next
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = " Computer Name "
objExcel.Cells(1, 1).Font.Colorindex = 2
objExcel.Cells(1, 1).Font.Bold = True
objExcel.Cells(1, 1).Interior.ColorIndex = 23
objExcel.Cells(1, 1).Alignment = "Center"
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 2).Value = " Manufacturer "
objExcel.Cells(1, 2).Font.Colorindex = 2
objExcel.Cells(1, 2).Font.Bold = True
objExcel.Cells(1, 2).Interior.ColorIndex = 23
Set objRange = objExcel.Range("B1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 3).Value = " Model "
objExcel.Cells(1, 3).Font.Colorindex = 2
objExcel.Cells(1, 3).Font.Bold = True
objExcel.Cells(1, 3).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 4).Value = " RAM (GB) "
objExcel.Cells(1, 4).Font.Colorindex = 2
objExcel.Cells(1, 4).Font.Bold = True
objExcel.Cells(1, 4).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 5).Value = " Operating System "
objExcel.Cells(1, 5).Font.Colorindex = 2
objExcel.Cells(1, 5).Font.Bold = True
objExcel.Cells(1, 5).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 6).Value = " Processor "
objExcel.Cells(1, 6).Font.Colorindex = 2
objExcel.Cells(1, 6).Font.Bold = True
objExcel.Cells(1, 6).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 7).Value = " Drive "
objExcel.Cells(1, 7).Font.Colorindex = 2
objExcel.Cells(1, 7).Font.Bold = True
objExcel.Cells(1, 7).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 8).Value = " Drive Size (GB)"
objExcel.Cells(1, 8).Font.Colorindex = 2
objExcel.Cells(1, 8).Font.Bold = True
objExcel.Cells(1, 8).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
objExcel.Cells(1, 9).Value = " Free Space (GB) "
objExcel.Cells(1, 9).Font.Colorindex = 2
objExcel.Cells(1, 9).Font.Bold = True
objExcel.Cells(1, 9).Interior.ColorIndex = 23
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = ObjExcel.ActiveCell.EntireColumn
objRange.AutoFit()
' Reading the Input File (Text File Containing Computer Names)
y = 2
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set pcfile = fso1.OpenTextFile("hosts.txt",1)
do while Not pcfile.AtEndOfStream
computerName = pcfile.readline
Err.Clear
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
computerName & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
Set colOSSettings = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
Set colProcSettings = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")
Set colDiskSettings = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType=3")
If Err.Number = 0 Then
For Each objComputer In colSettings
strManufacturer = objComputer.Manufacturer
strModel = objComputer.Model
'FormatGB = FormatNumber(size / (1024 * 1024 * 1024), 2,0,0,0)
strRAM = FormatNumber((objComputer.TotalPhysicalMemory / (1024 * 1024 *1024)), 2,0,0,0)
For Each objOS In colOSSettings
strOS = objOS.Caption
For Each objProc In colProcSettings
strProc = objProc.Name
If computerName <> oldName Then
objExcel.Cells(y, 1).Value = computerName
objExcel.Cells(y, 1).Alignment = "Center"
objExcel.Cells(y, 2).Value = strManufacturer
objExcel.Cells(y, 2).Alignment = "Center"
objExcel.Cells(y, 3).Value = strModel
objExcel.Cells(y, 3).Alignment = "Center"
objExcel.Cells(y, 4).Value = strRAM
objExcel.Cells(y, 4).Alignment = "Center"
objExcel.Cells(y, 5).Value = strOS
objExcel.Cells(y, 5).Alignment = "Center"
objExcel.Cells(y, 6).Value = strProc
objExcel.Cells(y, 6).Alignment = "Center"
For Each objDisk In colDiskSettings
strDiskDeviceID = objDisk.DeviceID
objExcel.Cells(y, 7).Value = strDiskDeviceID
objExcel.Cells(y, 7).Alignment = "Center"
'FormatNumber((objComputer.TotalPhysicalMemory / (1024 * 1024 *1024)), 2,0,0,0)
strDiskSize = FormatNumber((objDisk.Size / (1024 * 1024 * 1024)),2,0,0,0)
objExcel.Cells(y, 8).Value = strDiskSize
objExcel.Cells(y, 8).Alignment = "Center"
strDiskFreeSpace = FormatNumber((objDisk.FreeSpace / (1024 * 1024 * 1024)),2,0,0,0)
objExcel.Cells(y, 9).Value = strDiskFreeSpace
objExcel.Cells(y, 9).Alignment = "Center"
y = y + 1
Next
oldName = computerName
y = y + 1
End If
computerName = ""
strManufacturer = ""
strModel = ""
strRAM = ""
Err.clear
Next
Next
Next
Else
objExcel.Cells(y, 1).Value = computerName
objExcel.Cells(y, 1).Alignment = "Center"
objExcel.Cells(y, 2).Value = "Not on line"
objExcel.Cells(y, 2).Alignment = "Center"
y = y + 1
Err.clear
End If
Loop
y = y + 1
objExcel.Cells(y, 1).Value = "Scan Complete"
objExcel.Cells(y, 1).Font.Bold = True
et objRange = objExcel.Range("A1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("B1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("C1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()
Set objRange = objExcel.Range("D1")
objRange.Activate
Set objRange = objExcel.ActiveCell.EntireColumn
objRange.Autofit()