0% found this document useful (1 vote)
1K views21 pages

VBScript Windows Computer Inventory

This script remotely inventories a machine and exports the results to an Excel spreadsheet. It collects information on hardware, software, services and prints. It initializes objects to connect to the remote machine and Excel. It then queries WMI for system information and loads it into collections. It creates sheets in Excel for the different categories and loops through the collections, outputting attributes to cells with headers for easy reading.

Uploaded by

Brian Bohanon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
1K views21 pages

VBScript Windows Computer Inventory

This script remotely inventories a machine and exports the results to an Excel spreadsheet. It collects information on hardware, software, services and prints. It initializes objects to connect to the remote machine and Excel. It then queries WMI for system information and loads it into collections. It creates sheets in Excel for the different categories and loops through the collections, outputting attributes to cells with headers for easy reading.

Uploaded by

Brian Bohanon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

'*********************************************************************************

'Script to remotely inventory a machine


' Created by: Brian Bohanon
' Created: 6/11/2008
'*********************************************************************************
Option Explicit

Dim strComputer
Dim i, j
Dim objExcel, objFSO, objWMIService, objOSItem, objBIOS, objSetting
Dim objQuickFix, objPrintItem, objSoftware, objNet, objVideo
Dim objService, objDisk, objDiskDrive, objSCSIItem, objProcItem
Dim colBIOS, colDisks, colDiskDrives, colDrives, colNet, colOSItems
Dim colPrintItems, colProcItems, colVideo
Dim colQuickFixes, colSCSIItems, colServices, colSettings, colSoftware
Dim disk_size, disk_free, video_ram, diskDrive_size, phys_ram
'Get the computer name from user to begin processing
strComputer = InputBox("Computer to Inventory", "Computer Name")

'Initialize counter
i = 0

'Declare Constants
Const xlLeft = -4131
Const xlHorizontal = -4128

'Declare Objects
Set objExcel = CreateObject("[Link]")
Set objFSO = CreateObject("[Link]")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Initialize collections
Set colBIOS = [Link]("Select * from Win32_BIOS")
Set colDisks = [Link]("Select * from Win32_LogicalDisk")
Set colDiskDrives = [Link]("Select * from Win32_DiskDrive")
Set colDrives = [Link]
Set colNet = [Link]("Select * from Win32_NetworkAdapter")
Set colOSItems = [Link]("Select * from Win32_OperatingSystem")
Set colPrintItems = [Link]("Select * from Win32_Printer")
Set colProcItems = [Link]("Select * from Win32_Processor")
Set colQuickFixes = [Link]("Select * from
Win32_QuickFixEngineering")
Set colSCSIItems = [Link]("Select * from Win32_SCSIController")
Set colServices = [Link]("Select * From Win32_Service")
Set colSettings = [Link]("Select * from Win32_ComputerSystem")
Set colSoftware = [Link]("Select * from Win32_Product")
Set colVideo = [Link]("Select * from Win32_VideoController")

'*********************************************************************************
' Create a new and blank spreadsheet
'*********************************************************************************
[Link] = True
[Link]

'Setup the workbook


do while i <> 2
[Link]
i = i + 1
loop

'Create Sheet for computer name, os, install date, general information
[Link]("Sheet5").Name = strComputer
'Create Sheet named software
[Link]("Sheet4").Name = "Software"
'Create Sheet named services
[Link]("Sheet1").Name = "Services"
'Create Sheet named hardware - e.g. disk drives, memory, processor
[Link]("Sheet2").Name = "Hardware"
'Create Sheet named printers
[Link]("Sheet3").Name = "Printers"

'*********************************************************************************
'Computer information
'*********************************************************************************
'start the counter for all of the loops
i = 1 'row counter
j = 1 'column counter

' Section header


[Link](i, j).Value = "Computer Information"
[Link](i, j).[Link] = TRUE

i = i + 1

[Link](i, j).Value = "Computer Name: "


[Link](i, j).[Link] = TRUE

j = j + i

[Link](2, 2).Value = strComputer

'Get OS information

i = i + 2
j = 1

For Each objOSItem in colOSItems


[Link](i, j).Value = "Operating System:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "Description:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1
[Link](i, j).Value = "InstallDate:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "Organization:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "RegisteredUser:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "SerialNumber:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "ServicePackMajorVersion:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = "SP " & [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "ServicePackMinorVersion:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]


i = i + 1
j = j - 1

[Link](i, j).Value = "Version:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "WindowsDirectory:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1
Next

Set objOSItem = nothing

i = i + 1

'Section header
[Link](i, j).Value = "Physical Machine Information"
[Link](i, j).[Link] = TRUE

i = i + 1

'Insert hardware serial number


For each objBIOS in colBIOS
[Link](i, j).Value = "Serial Number"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]


Next

Set objBIOS = nothing

i = i + 1
j = 1

'Physical Machine information


For Each objSetting in colSettings
[Link](i, j).Value = "Manufacturer:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]


i = i + 1
j = j - 1

i = i + 1
j = 1

[Link](i, j).Value = "Model:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]

i = i + 1
j = j - 1

[Link](i, j).Value = "System Type:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = [Link]


Next

Set objSetting = nothing

' Autofit the columns


[Link]("A:Z").[Link]
[Link]("A:Z").HorizontalAlignment = xlLeft

'*********************************************************************************
'Software Information
'*********************************************************************************
'Activate the Software worksheet
[Link]("Software").Activate

i = 1
j = 1

[Link](i, j) = "Software"
[Link](i, j).[Link] = TRUE

i = i + 1

[Link](i, j) = "Caption:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Version:"
[Link](i, j).[Link] = TRUE

j = j + 1
[Link](i, j) = "Description:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Vendor:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Identiying Number:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Install Date:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Install Location:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Package Cache:"


[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

For Each objSoftware in colSoftware


[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = objSoftware.InstallDate2
j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = 1
i = i + 1
Next

Set objSoftware = nothing

i = i + 1
j = 1

'Section header
[Link](i, j) = "Installed Hotfixes"
[Link](i, j).[Link] = TRUE

i = i + 1

'Column headers
[Link](i, j) = "Hot Fix ID:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Description:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Installation Date:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Service Pack Level:"


[Link](i, j).[Link] = TRUE

'Hotfix data
For Each objQuickFix in colQuickFixes
i = i + 1
j = 1

If [Link] = "File 1" Then


[Link](i, j) = [Link]
Else
[Link](i, j) = [Link]
End If

j = j + 1

[Link](i, j) = [Link]
j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
Next

Set objQuickFix = nothing

' Autofit the columns


[Link]("A:Z").[Link]
[Link]("A:Z").HorizontalAlignment = xlLeft

'*********************************************************************************
'Services Information
'*********************************************************************************
'Activate the services worksheet
[Link]("Services").Activate

i = 1
j = 1

'Column headers
[Link](i, j).Value = "Service"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = "Status"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = "Start Mode"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = "Start Name"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j).Value = "Path Name"


[Link](i, j).[Link] = TRUE

'Services data
For Each objService in colServices
i = i + 1
j = 1
[Link](i, j) = [Link]
j = j + 1
[Link](i, j) = [Link]
j = j + 1
[Link](i, j) = [Link]
j = j + 1
[Link](i, j) = [Link]
j = j + 1
[Link](i, j) = [Link]
Next

Set objService = nothing

' Autofit the first column to fit the longest service name
[Link]("A:Z").[Link]
[Link]("A:Z").HorizontalAlignment = xlLeft

'*********************************************************************************
'Hardware Section
'*********************************************************************************
'Activate the hardware worksheet
[Link]("Hardware").Activate

i = 1
j = 1

'Section header
[Link](i, j) = "Logical Drives"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column headers
[Link](i, j) = "Drive letters:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Volume Name:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Description:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "File System:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Total Size (GB):"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Free Space (GB):"


[Link](i, j).[Link] = TRUE

j = j + 1
[Link](i, j) = "Volume Serial Number:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Compressed:"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Logical disk data


For each objDisk in colDisks
[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

disk_size = [Link] / 1073741824


[Link](i, j) = int(disk_size)

j = j + 1

disk_free = [Link] / 1073741824


[Link](i, j) = int(disk_free)

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = 1
i = i + 1
Next

Set objDisk = nothing

j = 1
i = i + 1

'Section header
[Link](i, j) = "Physical Drives"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column headers
[Link](i, j) = "Caption:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Device ID:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Index:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Interface Type:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Manufacturer:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Media Loaded:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Media Type:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Model:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Partitions:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "SCSI Bus:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "SCSI Logical Unit:"


[Link](i, j).[Link] = TRUE
j = j + 1

[Link](i, j) = "SCSI Port:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "SCSI TargetId:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Sectors Per Track:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Signature:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Size (GB):"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Status:"
[Link](i, j).[Link] = TRUE

'Physical disk data


For each objDiskDrive in colDiskDrives

i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

diskDrive_size = [Link] / 1073741824


[Link](i, j) = int(diskDrive_size)

j = j + 1

[Link](i, j) = [Link]

Next

Set objDiskDrive = nothing

'Get SCSI Controller

j = 1
i = i + 2

'Section header
[Link](i, j) = "SCSI Information"
[Link](i, j).[Link] = TRUE
i = i + 1
j = 1

'Column headers
[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Device ID:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Driver Name:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "PNP Device ID:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Protocol Supported:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Status Information:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Configuration Manager Error Code:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Configuration Manager User Configuration:"


[Link](i, j).[Link] = TRUE

'SCSI controller data


For Each objSCSIItem in colSCSIItems
i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
Next

Set objSCSIItem = nothing

'Get BIOS information

j = 1
i = i + 2

'Section header
[Link](i, j) = "BIOS Information"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column header
[Link](i, j) = "Manufacturer:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Release Date:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Version:"
[Link](i, j).[Link] = TRUE

'BIOS data
For each objBIOS in colBIOS
i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
Next

Set objBIOS = nothing

'Get Processor information

j = 1
i = i + 2

'Section header
[Link](i, j) = "Processor Information"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column headers
[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Manufacturer:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Current Clock Speed (MHz):"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "L2 Cache Size (MB):"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Architecture:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Address Width (bits):"


[Link](i, j).[Link] = TRUE

'Processor data
For Each objProcItem in colProcItems
i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = objProcItem.L2CacheSize

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

Next

Set objProcItem = nothing

'Get Memory Information

j = 1
i = i + 2

'Section header
[Link](i, j) = "Physical Memory Information"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column header
[Link](i, j) = "Total Physical Memory (MB):"
[Link](i, j).[Link] = TRUE

'Physical memory data


For Each objSetting in colSettings
i = i + 1
j = 1

phys_ram = [Link] / 1048576


[Link](i, j) = int(phys_ram)
Next
Set objSetting = nothing

'Get Video Information

j = 1
i = i + 2

'Section header
[Link](i, j) = "Video Card Information"
[Link](i, j).[Link] = TRUE

i = i + 1
j = 1

'Column header
[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Description:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Driver Version:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Video Memory (MB):"


[Link](i, j).[Link] = TRUE

'Video card data


For Each objVideo in colVideo
i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

video_ram = [Link] / 1048576


[Link](i, j) = int(video_ram)

Next

Set objVideo = nothing

'Get Network Adapter Information


j = 1
i = i + 2

'Section header
[Link](i, j) = "NIC Information"
[Link](i, j).[Link] = TRUE

'Column header
i = i + 1
j = 1

[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "MAC Address:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Manufacturer:"
[Link](i, j).[Link] = TRUE

'Network card data


For Each objNet in colNet

If [Link] <> "" Then


i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
End if
Next

Set objNet = nothing

' Autofit the first column to fit the longest name


[Link]("A:Z").[Link]
[Link]("A:Z").HorizontalAlignment = xlLeft

'*********************************************************************************
'Printers Section
'*********************************************************************************
'Activate printers worksheet
[Link]("Printers").Activate

i = 1
j = 1
'Section header
[Link](i, j) = "Printer Information"
[Link](i, j).[Link] = TRUE

'Column Headers
i = i + 1
j = 1

[Link](i, j) = "Default:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Name:"
[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Server Name:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Share Name:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Driver Name:"


[Link](i, j).[Link] = TRUE

j = j + 1

[Link](i, j) = "Port Name:"


[Link](i, j).[Link] = TRUE

'List printer objects


For Each objPrintItem in colPrintItems
i = i + 1
j = 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]

j = j + 1
[Link](i, j) = [Link]

j = j + 1

[Link](i, j) = [Link]
Next

Set objPrintItem = nothing

' Autofit the first column to fit the longest name


[Link]("A:Z").[Link]
[Link]("A:Z").HorizontalAlignment = xlLeft

'Activate the Main worksheet


[Link](strComputer).Activate

'*********************************************************************************
'Cleanup
'*********************************************************************************

'Cleanup objects
[Link]

Set objExcel = nothing


Set objFSO = nothing
Set objWMIService = nothing

'Initialize collections
Set colBIOS = nothing
Set colDisks = nothing
Set colDiskDrives = nothing
Set colDrives = nothing
Set colNet = nothing
Set colOSItems = nothing
Set colPrintItems = nothing
Set colProcItems = nothing
Set colQuickFixes = nothing
Set colSCSIItems = nothing
Set colServices = nothing
Set colSettings = nothing
Set colSoftware = nothing
Set colVideo = nothing

'Inform the user that the process is complete


[Link]("Finished")

[Link] 0

You might also like