-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInventory.vbs
More file actions
executable file
·233 lines (209 loc) · 7.83 KB
/
Copy pathInventory.vbs
File metadata and controls
executable file
·233 lines (209 loc) · 7.83 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Option Explicit
Dim strComputer, arrTMP, j, arrResults, Result, NestedResult, disktmp
strComputer = "term-server4"
disktmp = DiskData(strComputer)
Build disktmp, "test"
'*******************************************************
Private Function OSQuery(strComputer)
On Error Resume Next
Dim objWMIService, objItem, colItems
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT Primary, Caption FROM Win32_OperatingSystem where Primary=true",,48)
If Err = 0 Then
For Each objItem in colItems
OSQuery = objItem.Caption
Next
Else
OSQuery = "Not Found"
Err.Clear
End If
End Function
'*******************************************************
Private Function GetLastLogon(strComputer, OSPreVista)
Dim strKeyPath, objReg, subkey, arrsubkeys, RegCheck, ValueName
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const HKU = &H80000003 'HKEY_USERS
Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG
If OSPreVista Then
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
ValueName = "DefaultUserName"
Else
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI"
ValueName = "LastLoggedOnUser"
End If
Set objReg=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
objReg.GetStringValue HKLM, strkeyPath, valuename, regcheck
GetLastLogon = regcheck
End Function
'*******************************************************
Private Function GetCPUName(strComputer)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT Name FROM Win32_Processor",,48)
For Each objItem in colItems
GetCPUName = objItem.Name
Next
End Function
'*******************************************************
Private Function GetLogicalCPUCount(strComputer)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT NumberofProcessors FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
GetLogicalCPUCount = objItem.NumberofProcessors
Next
End Function
'*******************************************************
Private Function GetTotalRAM(strComputer)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT TotalPhysicalMemory FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
GetTotalRAM = FormatNumber(objItem.TotalPhysicalMemory/1024/1024,0) & " MB"
Next
End Function
'*******************************************************
Private Function DiskData(strComputer)
On Error Resume Next
Dim colPartitions, colDisks, colVolumes, colPerfMons
Dim objWMI, objPartition, objDisk, objVolume, objPerfmon
Dim arrResult(), arrPhysicalDisk(), intResultCount, intPhysicalDiskCount
intPhysicalDiskCount = -1
intResultCount = -1
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMI.ExecQuery("Select * From Win32_LogicalDisk Where drivetype = 3")
For Each objVolume in colVolumes
Set colPartitions = objWMI.ExecQuery("Associators of {Win32_LogicalDisk.DeviceID='" & objVolume.DeviceID & _
"'} WHERE RESULTCLASS = Win32_DiskPartition")
intResultCount = intResultCount + 6
Redim Preserve arrResult(intResultCount)
arrResult(intResultCount - 5) = objVolume.DeviceID 'DriveLetter
arrResult(intResultCount - 4) = objVolume.FileSystem 'FileSystem
arrResult(intResultCount - 3) = FormatNumber((objVolume.Size / 1024) / 1024, 2) 'PartitionSize
arrResult(intResultCount - 2) = FormatNumber((objVolume.Freespace / 1024) / 1024, 2) 'PartitionFreespace in MB
Err.Clear
Set colPerfMons = objWMI.ExecQuery( _
"SELECT PercentFreeSpace FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk where Name = '" & objVolume.DeviceID & "'",,48)
For Each objPerfmon in colPerfMons
IF Err <> 0 Then
arrResult(intResultCount - 1) = "NA"
Err.Clear
Else
arrResult(intResultCount - 1) = objPerfmon.PercentFreeSpace
End If
Next
For Each objPartition in colPartitions
intPhysicalDiskCount = intPhysicalDiskCount + 1
Redim Preserve arrPhysicalDisk(1,intPHysicalDiskCount)
arrPhysicalDisk(0,intPhysicalDiskCount) = objPartition.DeviceID
Set colDisks = objWMI.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & objPartition.DeviceID & _
"'} WHERE RESULTCLASS = Win32_DiskDrive")
For Each objDisk in colDisks
arrPhysicalDisk(1,intPhysicalDiskCount) = objDisk.Caption
Next
Next
arrResult(intResultCount) = arrPhysicalDisk
intPhysicalDiskCount = -1
Redim arrPHysicalDisk(1,0)
Next
DiskData = arrResult
End Function
'*******************************************************
Function UTCDateStrToSQLDateTime(strUTCDate)
Dim objRE,colMatches, strReturn
Set objRE = New RegExp
objRE.Global = True
objRE.ignorecase = false
objRE.Pattern = "^(\d{8})(\d{2})(\d{2})(.{6})"
strReturn = ""
Set colMatches = objRE.Execute(strUTCDate)
If colMatches.count >=1 Then
If (colMatches(0).submatches.count >= 4)Then
strReturn = colMatches(0).submatches(0) & " " & _
colMatches(0).submatches(1) & ":" & _
colMatches(0).submatches(2) & ":" & _
colMatches(0).submatches(3)
End If
End If
UTCDateStrToSQLDateTime = strReturn
End Function
'*******************************************************
Private Function GetInstalledApps(strComputer)
Dim objReg, strSubKey, arrSubKeys, errCheck, strValue, arrReturn(), i
Const HKLM = &H80000002
Const strBaseKey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
i=0
For Each strSubKey In arrSubKeys
errCheck = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "DisplayName", strValue)
If errCheck <> 0 Then
errCheck = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "QuietDisplayName", strValue)
End If
If (strValue <> "") and (errCheck = 0) Then
ReDim Preserve arrReturn(i)
arrReturn(i) = strValue
i = i + 1
End If
Next
GetInstalledApps = arrReturn
End Function
'*******************************************************
Private Function Build(arrResults, strRepeatedData)
Dim Result, i, intFormatCounter, strTMP, strPhysicalDiskTMP, j, strOutput
intFormatCounter = 0
strTMP = strRepeatedData
j = 0
For each result in arrResults
j = j + 1
If IsArray(Result) Then
For i=0 to Ubound(Result,2)
strPhysicalDiskTMP = Result(0,i) & "(" & Result(1,i) & ")" & strPhysicalDiskTMP
wscript.echo "Physical Disk: " & Result(0,i)
wscript.echo "Caption: " & Result(1,i)
If i < Ubound(Result,2) Then
strPhysicalDiskTMP = "/" & strPhysicalDiskTMP
End If
Next
strTMP = strTMP & vbtab & strPhysicalDiskTMP
strPhysicalDiskTMP = ""
Else
Select Case intFormatCounter
Case 0
wscript.echo "Drive Letter: " & Result
strTMP = Result
Case 1
wscript.echo "File System: " & Result
strTMP = strTMP & vbtab & Result
Case 2
wscript.echo "Partion Size in MB: " & Result
strTMP = strTMP & vbtab & Result
Case 3
wscript.echo "Freespace in MB: " & Result
strTMP = strTMP & vbtab & Result
Case 4
wscript.echo "Percent Freespace: " & Result
strTMP = strTMP & vbtab & Result
End Select
End If
If intFormatCounter < 5 Then
intFormatCounter = intFormatCounter +1
Else
intFormatCounter = 0
if j < Ubound(arrResults) Then
strOutput = strOutput & strRepeatedData & strTMP & vbcrlf
Else
strOutput = strOutput & strRepeatedData & strTMP
End If
End If
Next
wscript.echo strOutput
Build = strOutput
End Function