-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet-Inventory.ps1
More file actions
642 lines (576 loc) · 25.1 KB
/
Get-Inventory.ps1
File metadata and controls
642 lines (576 loc) · 25.1 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
<#
#########################################
# Originating Author: Jesse Hamrick #
# Modifying Author: Dallas Moore #
# Date created: Feb 2009 #
# Last updated: May 2015 #
# Ver: 2.0 #
#########################################
.SYNOPSIS
Inventories hardware and software configuration of a target machine.
.DEPENDENCIES
Microsoft Excel MUST be installed on the target machine.
.DESCRIPTION
The purpose of this script is to generate a hardware and software configuration
report for a target machine. In it's original form, this script gathered the
CPU, Memory, BIOS, HDD, and network configuration information, but has since
been updated to gather expanded network configuration, installed software, running services,
and patch information. Information gathered is output to an Excel spreadsheet.
.EXAMPLE
PS C:\Personal\dmoore\Documents\Powershell Scripts> .\Get-Inventory.ps1
Admin rights are required to enumerate information.
Would you like to use an alternative credential?
[Y] Yes, [N] No: n
Which computer resources would you like in the report?
[1] All Domain Computers, [2] All Domain Servers, [3] Computer names from a File, [4] Choose a Computer manually: 4
Enter Computer Name or IP: localhost
.NOTE1
If you're interested in checking out the original script, see here:
http://www.powershellpro.com/why-i-no-longer-hate-writing-documentation/614/
.NOTE2
In the future, I would like to modify this script so that it writes output to a database
rather than to Excel.
#>
# ==============================================================================================
# Functions Section
# ==============================================================================================
# Function Name 'WMILookup' - Gathers info using WMI and places results in Excel
# ==============================================================================================
Function WMILookup {
foreach ($StrComputer in $colComputers){
$GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
$GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer
$SysItems1 = gwmi Win32_BIOS -Comp $StrComputer
$SysItems2 = gwmi Win32_TimeZone -Comp $StrComputer
$SysItems3 = gwmi Win32_WmiSetting -Comp $StrComputer
$ProcItems1 = gwmi Win32_Processor -Comp $StrComputer
$MemItems1 = gwmi Win32_PhysicalMemory -Comp $StrComputer
$memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $StrComputer
$DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer
$NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $StrComputer |`
where{$_.IPEnabled -eq "True"}
$PatchItems = gwmi -class win32_quickfixengineering -Comp $StrComputer | Sort -Property InstalledOn -Descending
$SoftwareInfo = gwmi Win32_Product -Comp $StrComputer | Sort -Property Name
$ServiceInfo = gwmi Win32_Service | Where {$_.State -eq "Running"}
# Populate General Sheet(1) with information
foreach ($objItem in $GenItems1){
$Sheet1.Cells.Item($intRow, 1) = $StrComputer
Switch($objItem.DomainRole)
{
0{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Workstation"}
1{$Sheet1.Cells.Item($intRow, 2) = "Member Workstation"}
2{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Server"}
3{$Sheet1.Cells.Item($intRow, 2) = "Member Server"}
4{$Sheet1.Cells.Item($intRow, 2) = "Back-up Domain Controller"}
5{$Sheet1.Cells.Item($intRow, 2) = "Primary Domain Controller"}
default{"Undetermined"}
}
$Sheet1.Cells.Item($intRow, 3) = $objItem.Manufacturer
$Sheet1.Cells.Item($intRow, 4) = $objItem.Model
$Sheet1.Cells.Item($intRow, 5) = $objItem.SystemType
$Sheet1.Cells.Item($intRow, 6) = $objItem.NumberOfProcessors
$Sheet1.Cells.Item($intRow, 7) = $objItem.TotalPhysicalMemory / 1024 / 1024
}
foreach ($objItem in $GenItems2){
$Sheet1.Cells.Item($intRow, 8) = $objItem.Caption
$Sheet1.Cells.Item($intRow, 9) = $objItem.csdversion
}
#Populate Systems Sheet
foreach ($objItem in $SysItems1){
$Sheet2.Cells.Item($intRow, 1) = $StrComputer
$Sheet2.Cells.Item($intRow, 2) = $objItem.Name
$Sheet2.Cells.Item($intRow, 3) = $objItem.SMBIOSbiosVersion
$Sheet2.Cells.Item($intRow, 4) = $objItem.SerialNumber
}
foreach ($objItem in $SysItems2){
$Sheet2.Cells.Item($intRow, 5) = $objItem.Caption
}
foreach ($objItem in $SysItems3){
$Sheet2.Cells.Item($intRow, 6) = $objItem.BuildVersion
}
#Populate Processor Sheet
foreach ($objItem in $ProcItems1){
$Sheet3.Cells.Item($intRowCPU, 1) = $StrComputer
$Sheet3.Cells.Item($intRowCPU, 2) = $objItem.DeviceID+" "+$objItem.Name
$Sheet3.Cells.Item($intRowCPU, 3) = $objItem.Description
$Sheet3.Cells.Item($intRowCPU, 4) = $objItem.family
$Sheet3.Cells.Item($intRowCPU, 5) = $objItem.currentClockSpeed
$Sheet3.Cells.Item($intRowCPU, 6) = $objItem.l2cacheSize
$Sheet3.Cells.Item($intRowCPU, 7) = $objItem.UpgradeMethod
$Sheet3.Cells.Item($intRowCPU, 8) = $objItem.SocketDesignation
$intRowCPU = $intRowCPU + 1
}
#Populate Memory Sheet
$bankcounter = 1
foreach ($objItem in $memItems2){
$MemSlots = $objItem.MemoryDevices +1
foreach ($objItem in $MemItems1){
$Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
$Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
if($objItem.BankLabel -eq ""){
$Sheet4.Cells.Item($intRowMem, 3) = $objItem.DeviceLocator}
Else{$Sheet4.Cells.Item($intRowMem, 3) = $objItem.BankLabel}
$Sheet4.Cells.Item($intRowMem, 4) = $objItem.Capacity/1024/1024
$Sheet4.Cells.Item($intRowMem, 5) = $objItem.FormFactor
$Sheet4.Cells.Item($intRowMem, 6) = $objItem.TypeDetail
$intRowMem = $intRowMem + 1
$bankcounter = $bankcounter + 1
}
while($bankcounter -lt $MemSlots)
{
$Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
$Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
$Sheet4.Cells.Item($intRowMem, 3) = "is Empty"
$Sheet4.Cells.Item($intRowMem, 4) = ""
$Sheet4.Cells.Item($intRowMem, 5) = ""
$Sheet4.Cells.Item($intRowMem, 6) = ""
$intRowMem = $intRowMem + 1
$bankcounter = $bankcounter + 1
}
}
#Populate Disk Sheet
foreach ($objItem in $DiskItems){
$Sheet5.Cells.Item($intRowDisk, 1) = $StrComputer
Switch($objItem.DriveType)
{
2{$Sheet5.Cells.Item($intRowDisk, 2) = "Floppy"}
3{$Sheet5.Cells.Item($intRowDisk, 2) = "Fixed Disk"}
5{$Sheet5.Cells.Item($intRowDisk, 2) = "Removable Media"}
default{"Undetermined"}
}
$Sheet5.Cells.Item($intRowDisk, 3) = $objItem.DeviceID
$Sheet5.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024
$Sheet5.Cells.Item($intRowDisk, 5) = $objItem.FreeSpace/1024/1024
$intRowDisk = $intRowDisk + 1
}
#Populate Network Sheet
foreach ($objItem in $NetItems){
$Sheet6.Cells.Item($intRowNet, 1) = $StrComputer
$Sheet6.Cells.Item($intRowNet, 2) = $objItem.Caption+" (enabled)"
$Sheet6.Cells.Item($intRowNet, 3) = $objItem.DHCPEnabled
$Sheet6.Cells.Item($intRowNet, 4) = $objItem.IPAddress
$Sheet6.Cells.Item($intRowNet, 5) = $objItem.IPSubnet
$Sheet6.Cells.Item($intRowNet, 6) = $objItem.DefaultIPGateway
$Sheet6.Cells.Item($intRowNet, 7) = $objItem.DNSServerSearchOrder
$Sheet6.Cells.Item($intRowNet, 8) = $objItem.FullDNSRegistrationEnabled
$Sheet6.Cells.Item($intRowNet, 9) = $objItem.WINSPrimaryServer
$Sheet6.Cells.Item($intRowNet, 10) = $objItem.WINSSecondaryServer
$Sheet6.Cells.Item($intRowNet, 11) = $objItem.WINSEnableLMHostsLookup
$Sheet6.Cells.Item($intRowNet, 12) = $objItem.MACAddress
$Sheet6.Cells.Item($intRowNet, 13) = $objItem.DNSHostName
$Sheet6.Cells.Item($intRowNet, 14) = $objItem.DNSDomain
$intRowNet = $intRowNet + 1
}
#Populate Patches Sheet
foreach ($objItem in $PatchItems){
$Sheet7.Cells.Item($intRowPatch, 1) = $StrComputer
$Sheet7.Cells.Item($intRowPatch, 2) = $objItem.Description
$Sheet7.Cells.Item($intRowPatch, 3) = $objItem.HotFixID
$Sheet7.Cells.Item($intRowPatch, 4) = $objItem.InstalledBy
$Sheet7.Cells.Item($intRowPatch, 5) = $objItem.InstalledOn
$intRowPatch = $intRowPatch + 1
}
#Populate Installed Software Sheet
foreach ($objItem in $SoftwareInfo){
$Sheet8.Cells.Item($intRowSoft, 1) = $StrComputer
$Sheet8.Cells.Item($intRowSoft, 2) = $objItem.Name
$Sheet8.Cells.Item($intRowSoft, 3) = $objItem.Caption
$Sheet8.Cells.Item($intRowSoft, 4) = $objItem.Vendor
$Sheet8.Cells.Item($intRowSoft, 5) = $objItem.Version
$Sheet8.Cells.Item($intRowSoft, 6) = $objItem.IdentifyingNumber
$intRowSoft = $intRowSoft + 1
}
#Populate Runing Services
foreach ($objItem in $ServiceInfo){
$Sheet9.Cells.Item($intRowServ, 1) = $StrComputer
$Sheet9.Cells.Item($intRowServ, 2) = $objItem.DisplayName
$Sheet9.Cells.Item($intRowServ, 3) = $objItem.Name
$Sheet9.Cells.Item($intRowServ, 4) = $objItem.ProcessId
$Sheet9.Cells.Item($intRowServ, 5) = $objItem.StartMode
$Sheet9.Cells.Item($intRowServ, 6) = $objItem.State
$Sheet9.Cells.Item($intRowServ, 7) = $objItem.Status
$Sheet9.Cells.Item($intRowServ, 8) = $objItem.PathName
$intRowServ = $intRowServ + 1
}
$intRow = $intRow + 1
$intRowCPU = $intRowCPU + 1
$intRowMem = $intRowMem + 1
$intRowDisk = $intRowDisk + 1
$intRowNet = $intRowNet + 1
$intRowPatch = $intRowPatch + 1
$intRowSoft = $intRowSoft + 1
$intRowServ = $intRowServ + 1
}
}
# ==============================================================================================
# Function Name 'WMILookupCred'-Uses Alternative Credential-Gathers info using WMI.
# ==============================================================================================
Function WMILookupCred {
foreach ($StrComputer in $colComputers){
$GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer -Credential $cred
$GenItems2 = gwmi Win32_OperatingSystem -Comp $StrComputer -Credential $cred
$SysItems1 = gwmi Win32_BIOS -Comp $StrComputer -Credential $cred
$SysItems2 = gwmi Win32_TimeZone -Comp $StrComputer -Credential $cred
$SysItems3 = gwmi Win32_WmiSetting -Comp $StrComputer -Credential $cred
$ProcItems1 = gwmi Win32_Processor -Comp $StrComputer -Credential $cred
$MemItems1 = gwmi Win32_PhysicalMemory -Comp $StrComputer -Credential $cred
$memItems2 = gwmi Win32_PhysicalMemoryArray -Comp $StrComputer -Credential $cred
$DiskItems = gwmi Win32_LogicalDisk -Comp $StrComputer -Credential $cred
$NetItems = gwmi Win32_NetworkAdapterConfiguration -Comp $StrComputer -Credential $cred |`
where{$_.IPEnabled -eq "True"}
$PatchItems = gwmi -class win32_quickfixengineering -Comp $StrComputer
$SoftwareInfo = gwmi Win32_Product -Comp $StrComputer | Sort -Property Name
$ServiceInfo = gwmi Win32_Service | Where {$_.State -eq "Running"}
# Populate General Sheet(1) with information
foreach ($objItem in $GenItems1){
$Sheet1.Cells.Item($intRow, 1) = $StrComputer
Switch($objItem.DomainRole)
{
0{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Workstation"}
1{$Sheet1.Cells.Item($intRow, 2) = "Member Workstation"}
2{$Sheet1.Cells.Item($intRow, 2) = "Stand Alone Server"}
3{$Sheet1.Cells.Item($intRow, 2) = "Member Server"}
4{$Sheet1.Cells.Item($intRow, 2) = "Back-up Domain Controller"}
5{$Sheet1.Cells.Item($intRow, 2) = "Primary Domain Controller"}
default{"Undetermined"}
}
$Sheet1.Cells.Item($intRow, 3) = $objItem.Manufacturer
$Sheet1.Cells.Item($intRow, 4) = $objItem.Model
$Sheet1.Cells.Item($intRow, 5) = $objItem.SystemType
$Sheet1.Cells.Item($intRow, 6) = $objItem.NumberOfProcessors
$Sheet1.Cells.Item($intRow, 7) = $objItem.TotalPhysicalMemory / 1024 / 1024
}
foreach ($objItem in $GenItems2){
$Sheet1.Cells.Item($intRow, 8) = $objItem.Caption
$Sheet1.Cells.Item($intRow, 9) = $objItem.csdversion
}
#Populate Systems Sheet
foreach ($objItem in $SysItems1){
$Sheet2.Cells.Item($intRow, 1) = $StrComputer
$Sheet2.Cells.Item($intRow, 2) = $objItem.Name
$Sheet2.Cells.Item($intRow, 3) = $objItem.SMBIOSbiosVersion
$Sheet2.Cells.Item($intRow, 4) = $objItem.SerialNumber
}
foreach ($objItem in $SysItems2){
$Sheet2.Cells.Item($intRow, 5) = $objItem.Caption
}
foreach ($objItem in $SysItems3){
$Sheet2.Cells.Item($intRow, 6) = $objItem.BuildVersion
}
#Populate Processor Sheet
foreach ($objItem in $ProcItems1){
$Sheet3.Cells.Item($intRowCPU, 1) = $StrComputer
$Sheet3.Cells.Item($intRowCPU, 2) = $objItem.DeviceID+" "+$objItem.Name
$Sheet3.Cells.Item($intRowCPU, 3) = $objItem.Description
$Sheet3.Cells.Item($intRowCPU, 4) = $objItem.family
$Sheet3.Cells.Item($intRowCPU, 5) = $objItem.currentClockSpeed
$Sheet3.Cells.Item($intRowCPU, 6) = $objItem.l2cacheSize
$Sheet3.Cells.Item($intRowCPU, 7) = $objItem.UpgradeMethod
$Sheet3.Cells.Item($intRowCPU, 8) = $objItem.SocketDesignation
$intRowCPU = $intRowCPU + 1
}
#Populate Memory Sheet
$bankcounter = 1
foreach ($objItem in $memItems2){
$MemSlots = $objItem.MemoryDevices +1
foreach ($objItem in $MemItems1){
$Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
$Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
if($objItem.BankLabel -eq ""){
$Sheet4.Cells.Item($intRowMem, 3) = $objItem.DeviceLocator}
Else{$Sheet4.Cells.Item($intRowMem, 3) = $objItem.BankLabel}
$Sheet4.Cells.Item($intRowMem, 4) = $objItem.Capacity/1024/1024
$Sheet4.Cells.Item($intRowMem, 5) = $objItem.FormFactor
$Sheet4.Cells.Item($intRowMem, 6) = $objItem.TypeDetail
$intRowMem = $intRowMem + 1
$bankcounter = $bankcounter + 1
}
while($bankcounter -lt $MemSlots)
{
$Sheet4.Cells.Item($intRowMem, 1) = $StrComputer
$Sheet4.Cells.Item($intRowMem, 2) = "Bank " +$bankcounter
$Sheet4.Cells.Item($intRowMem, 3) = "is Empty"
$Sheet4.Cells.Item($intRowMem, 4) = ""
$Sheet4.Cells.Item($intRowMem, 5) = ""
$Sheet4.Cells.Item($intRowMem, 6) = ""
$intRowMem = $intRowMem + 1
$bankcounter = $bankcounter + 1
}
}
#Populate Disk Sheet
foreach ($objItem in $DiskItems){
$Sheet5.Cells.Item($intRowDisk, 1) = $StrComputer
Switch($objItem.DriveType)
{
2{$Sheet5.Cells.Item($intRowDisk, 2) = "Floppy"}
3{$Sheet5.Cells.Item($intRowDisk, 2) = "Fixed Disk"}
5{$Sheet5.Cells.Item($intRowDisk, 2) = "Removable Media"}
default{"Undetermined"}
}
$Sheet5.Cells.Item($intRowDisk, 3) = $objItem.DeviceID
$Sheet5.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024
$Sheet5.Cells.Item($intRowDisk, 5) = $objItem.FreeSpace/1024/1024
$intRowDisk = $intRowDisk + 1
}
#Populate Network Sheet
foreach ($objItem in $NetItems){
$Sheet6.Cells.Item($intRowNet, 1) = $StrComputer
$Sheet6.Cells.Item($intRowNet, 2) = $objItem.Caption+" (enabled)"
$Sheet6.Cells.Item($intRowNet, 3) = $objItem.DHCPEnabled
$Sheet6.Cells.Item($intRowNet, 4) = $objItem.IPAddress
$Sheet6.Cells.Item($intRowNet, 5) = $objItem.IPSubnet
$Sheet6.Cells.Item($intRowNet, 6) = $objItem.DefaultIPGateway
$Sheet6.Cells.Item($intRowNet, 7) = $objItem.DNSServerSearchOrder
$Sheet6.Cells.Item($intRowNet, 8) = $objItem.FullDNSRegistrationEnabled
$Sheet6.Cells.Item($intRowNet, 9) = $objItem.WINSPrimaryServer
$Sheet6.Cells.Item($intRowNet, 10) = $objItem.WINSSecondaryServer
$Sheet6.Cells.Item($intRowNet, 11) = $objItem.WINSEnableLMHostsLookup
$Sheet6.Cells.Item($intRowNet, 12) = $objItem.MACAddress
$Sheet6.Cells.Item($intRowNet, 13) = $objItem.DNSHostName
$Sheet6.Cells.Item($intRowNet, 14) = $objItem.DNSDomain
$intRowNet = $intRowNet + 1
}
#Populate Patches Sheet
foreach ($objItem in $PatchItems){
$Sheet7.Cells.Item($intRowPatch, 1) = $StrComputer
$Sheet7.Cells.Item($intRowPatch, 2) = $objItem.Description
$Sheet7.Cells.Item($intRowPatch, 3) = $objItem.HotFixID
$Sheet7.Cells.Item($intRowPatch, 4) = $objItem.InstalledBy
$Sheet7.Cells.Item($intRowPatch, 5) = $objItem.InstalledOn
$intRowPatch = $intRowPatch + 1
}
#Populate Installed Software Sheet
foreach ($objItem in $SoftwareInfo){
$Sheet8.Cells.Item($intRowSoft, 1) = $StrComputer
$Sheet8.Cells.Item($intRowSoft, 2) = $objItem.Name
$Sheet8.Cells.Item($intRowSoft, 3) = $objItem.Caption
$Sheet8.Cells.Item($intRowSoft, 4) = $objItem.Vendor
$Sheet8.Cells.Item($intRowSoft, 5) = $objItem.Version
$Sheet8.Cells.Item($intRowSoft, 6) = $objItem.IdentifyingNumber
$intRowSoft = $intRowSoft + 1
}
#Populate Runing Services
foreach ($objItem in $ServiceInfo){
$Sheet9.Cells.Item($intRowServ, 1) = $StrComputer
$Sheet9.Cells.Item($intRowServ, 2) = $objItem.DisplayName
$Sheet9.Cells.Item($intRowServ, 3) = $objItem.Name
$Sheet9.Cells.Item($intRowServ, 4) = $objItem.ProcessId
$Sheet9.Cells.Item($intRowServ, 5) = $objItem.StartMode
$Sheet9.Cells.Item($intRowServ, 6) = $objItem.State
$Sheet9.Cells.Item($intRowServ, 7) = $objItem.Status
$Sheet9.Cells.Item($intRowServ, 8) = $objItem.PathName
$intRowServ = $intRowServ + 1
}
$intRow = $intRow + 1
$intRowCPU = $intRowCPU + 1
$intRowMem = $intRowMem + 1
$intRowDisk = $intRowDisk + 1
$intRowNet = $intRowNet + 1
$intRowPatch = $intRowPatch + 1
$intRowSoft = $intRowSoft + 1
$intRowServ = $intRowServ + 1
}
}
# =============================================================================================
# Function Name 'ListComputers' - Enumerates ALL computer objects in AD
# ==============================================================================================
Function ListComputers {
$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{$objComputer = $objResult.Properties; $objComputer.name}
}
# ==============================================================================================
# Function Name 'ListServers' - Enumerates ALL Servers objects in AD
# ==============================================================================================
Function ListServers {
$strCategory = "computer"
$strOS = "Windows*Server*"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(&(objectCategory=$strCategory)(OperatingSystem=$strOS))")
$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{$objComputer = $objResult.Properties; $objComputer.name}
}
# ========================================================================
# Function Name 'ListTextFile' - Enumerates Computer Names in a text file
# Create a text file and enter the names of each computer. One computer
# name per line. Supply the path to the text file when prompted.
# ========================================================================
Function ListTextFile {
$strText = Read-Host "Enter the path for the text file"
$colComputers = Get-Content $strText
}
# ========================================================================
# Function Name 'SingleEntry' - Enumerates Computer from user input
# ========================================================================
Function ManualEntry {
$colComputers = Read-Host "Enter Computer Name or IP"
}
# ==============================================================================================
# Script Body
# ==============================================================================================
$erroractionpreference = "SilentlyContinue"
#Gather info from user.
Write-Host "Admin rights are required to enumerate information." -ForegroundColor Green
Write-Host "Would you like to use an alternative credential?" -ForegroundColor Green
$credResponse = Read-Host "[Y] Yes, [N] No"
If($CredResponse -eq "y"){$cred = Get-Credential DOMAIN\USER}
Write-Host " "
Write-Host "Which computer resources would you like in the report?" -ForegroundColor Green
$strResponse = Read-Host "[1] All Domain Computers, [2] All Domain Servers, [3] Computer names from a File, [4] Choose a Computer manually"
If($strResponse -eq "1"){$colComputers = ListComputers | Sort-Object}
elseif($strResponse -eq "2"){$colComputers = ListServers | Sort-Object}
elseif($strResponse -eq "3"){. ListTextFile}
elseif($strResponse -eq "4"){. ManualEntry}
else{Write-Host "You did not supply a correct response, `
Please run script again." -foregroundColor Red}
Write-Progress -Activity "Getting Inventory" -status "Running..." -id 1
#New Excel Application
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
# Create 8 worksheets
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
$Sheet = $Excel.Worksheets.Add()
# Assign each worksheet to a variable and
# name the worksheet.
$Sheet1 = $Excel.Worksheets.Item(1)
$Sheet2 = $Excel.WorkSheets.Item(2)
$Sheet3 = $Excel.WorkSheets.Item(3)
$Sheet4 = $Excel.WorkSheets.Item(4)
$Sheet5 = $Excel.WorkSheets.Item(5)
$Sheet6 = $Excel.WorkSheets.Item(6)
$Sheet7 = $Excel.WorkSheets.Item(7)
$Sheet8 = $Excel.WorkSheets.Item(8)
$Sheet9 = $Excel.WorkSheets.Item(9)
$Sheet1.Name = "General"
$Sheet2.Name = "System"
$Sheet3.Name = "Processor"
$Sheet4.Name = "Memory"
$Sheet5.Name = "Disk"
$Sheet6.Name = "Network"
$Sheet7.Name = "Patches"
$Sheet8.Name = "Software"
$Sheet9.Name = "Services"
#Create Heading for General Sheet
$Sheet1.Cells.Item(1,1) = "Device_Name"
$Sheet1.Cells.Item(1,2) = "Role"
$Sheet1.Cells.Item(1,3) = "HW_Make"
$Sheet1.Cells.Item(1,4) = "HW_Model"
$Sheet1.Cells.Item(1,5) = "HW_Type"
$Sheet1.Cells.Item(1,6) = "CPU_Count"
$Sheet1.Cells.Item(1,7) = "Memory_MB"
$Sheet1.Cells.Item(1,8) = "Operating_System"
$Sheet1.Cells.Item(1,9) = "SP_Level"
#Create Heading for System Sheet
$Sheet2.Cells.Item(1,1) = "Device_Name"
$Sheet2.Cells.Item(1,2) = "BIOS_Name"
$Sheet2.Cells.Item(1,3) = "BIOS_Version"
$Sheet2.Cells.Item(1,4) = "HW_Serial_#"
$Sheet2.Cells.Item(1,5) = "Time_Zone"
$Sheet2.Cells.Item(1,6) = "WMI_Version"
#Create Heading for Processor Sheet
$Sheet3.Cells.Item(1,1) = "Device_Name"
$Sheet3.Cells.Item(1,2) = "Processor(s)"
$Sheet3.Cells.Item(1,3) = "Type"
$Sheet3.Cells.Item(1,4) = "Family"
$Sheet3.Cells.Item(1,5) = "Speed_MHz"
$Sheet3.Cells.Item(1,6) = "Cache_Size_MB"
$Sheet3.Cells.Item(1,7) = "Interface"
$Sheet3.Cells.Item(1,8) = "#_of_Sockets"
#Create Heading for Memory Sheet
$Sheet4.Cells.Item(1,1) = "Device_Name"
$Sheet4.Cells.Item(1,2) = "Bank_#"
$Sheet4.Cells.Item(1,3) = "Label"
$Sheet4.Cells.Item(1,4) = "Capacity_MB"
$Sheet4.Cells.Item(1,5) = "Form"
$Sheet4.Cells.Item(1,6) = "Type"
#Create Heading for Disk Sheet
$Sheet5.Cells.Item(1,1) = "Device_Name"
$Sheet5.Cells.Item(1,2) = "Disk_Type"
$Sheet5.Cells.Item(1,3) = "Drive_Letter"
$Sheet5.Cells.Item(1,4) = "Capacity_MB"
$Sheet5.Cells.Item(1,5) = "Free_Space_MB"
#Create Heading for Network Sheet
$Sheet6.Cells.Item(1,1) = "Device_Name"
$Sheet6.Cells.Item(1,2) = "Network_Card"
$Sheet6.Cells.Item(1,3) = "DHCP_Enabled"
$Sheet6.Cells.Item(1,4) = "IP_Address"
$Sheet6.Cells.Item(1,5) = "Subnet_Mask"
$Sheet6.Cells.Item(1,6) = "Default_Gateway"
$Sheet6.Cells.Item(1,7) = "DNS_Servers"
$Sheet6.Cells.Item(1,8) = "DNS_Reg"
$Sheet6.Cells.Item(1,9) = "Primary_WINS"
$Sheet6.Cells.Item(1,10) = "Secondary_WINS"
$Sheet6.Cells.Item(1,11) = "WINS_Lookup"
$Sheet6.Cells.Item(1,12) = "MAC_Address"
$Sheet6.Cells.Item(1,13) = "DNS_Host_Name"
$Sheet6.Cells.Item(1,14) = "DNS_Domain"
#Create Heading for Patches Sheet
$Sheet7.Cells.Item(1,1) = "Device_Name"
$Sheet7.Cells.Item(1,2) = "Description"
$Sheet7.Cells.Item(1,3) = "HotFix_ID"
$Sheet7.Cells.Item(1,4) = "Installed_By"
$Sheet7.Cells.Item(1,5) = "Installed_On"
#Create Heading for Software Sheet
$Sheet8.Cells.Item(1,1) = "Device_Name"
$Sheet8.Cells.Item(1,2) = "Software_Name"
$Sheet8.Cells.Item(1,3) = "Caption"
$Sheet8.Cells.Item(1,4) = "Vendor"
$Sheet8.Cells.Item(1,5) = "Version"
$Sheet8.Cells.Item(1,6) = "Identifying_Number"
#Create Heading for Services Sheet
$Sheet9.Cells.Item(1,1) = "Device_Name"
$Sheet9.Cells.Item(1,2) = "Display_Name"
$Sheet9.Cells.Item(1,3) = "System_Name"
$Sheet9.Cells.Item(1,4) = "Process_ID"
$Sheet9.Cells.Item(1,5) = "Start_Mode"
$Sheet9.Cells.Item(1,6) = "Service_State"
$Sheet9.Cells.Item(1,7) = "Service_Status"
$Sheet9.Cells.Item(1,8) = "Path_Name"
$colSheets = ($Sheet1, $Sheet2, $Sheet3, $Sheet4, $Sheet5, $Sheet6, $Sheet7, $Sheet8, $Sheet9)
foreach ($colorItem in $colSheets){
$intRow = 2
$intRowCPU = 2
$intRowMem = 2
$intRowDisk = 2
$intRowNet = 2
$intRowPatch = 2
$intRowSoft = 2
$intRowServ = 2
$WorkBook = $colorItem.UsedRange
$WorkBook.Interior.ColorIndex = 20
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
}
If($credResponse -eq "y"){WMILookupCred}
Else{WMILookup}
#Auto Fit all sheets in the Workbook
foreach ($colorItem in $colSheets){
$WorkBook = $colorItem.UsedRange
$WorkBook.EntireColumn.AutoFit()
clear
}
Write-Host "*******************************" -ForegroundColor Green
Write-Host "The Report has been completed." -ForeGroundColor Green
Write-Host "*******************************" -ForegroundColor Green
# ========================================================================
# END of Script
# ========================================================================