Tuesday, June 17, 2008

VBSScript to Inventory Windows Computer

As part of a goal for 2008, I wanted to get a list of services running on a given Windows computer, including the accounts used and the startup mode. Once that script was written, it was much too easy to continue gathering relevant information for a system. The script below is the result.

'******************************************************************************************
'Script to remotely inventory a machine
' Created by: Brian Bohanon
' Created: 6/11/2008
'******************************************************************************************

'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("Excel.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

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

'*******************************************************************************************
' Create a new and blank spreadsheet
'*******************************************************************************************
objExcel.Visible = True
objExcel.Workbooks.Add

'Setup the workbook
do while i <> 2
objExcel.Worksheets.Add
i = i + 1
loop

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

'*****************************************************************************************
'Computer information
'*****************************************************************************************

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

' Section header
objExcel.Cells(i, j).Value = "Computer Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1

objExcel.Cells(i, j).Value = "Computer Name: "
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + i

objExcel.Cells(2, 2).Value = strComputer

'Get OS information

i = i + 2
j = 1

For Each objOSItem in colOSItems
objExcel.Cells(i, j).Value = "Operating System:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.Caption

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "Description:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.Description

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "InstallDate:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.InstallDate

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "Organization:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.Organization

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "RegisteredUser:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.RegisteredUser

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "SerialNumber:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.SerialNumber

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "ServicePackMajorVersion:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = "SP " & objOSItem.ServicePackMajorVersion

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "ServicePackMinorVersion:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.ServicePackMinorVersion

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "Version:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.Version

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "WindowsDirectory:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objOSItem.WindowsDirectory

i = i + 1
j = j - 1
Next

Set objOSItem = nothing

i = i + 1

'Section header
objExcel.Cells(i, j).Value = "Physical Machine Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1

'Insert hardware serial number
For each objBIOS in colBIOS
objExcel.Cells(i, j).Value = "Serial Number"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objBIOS.SerialNumber
Next

Set objBIOS = nothing

i = i + 1
j = 1

'Physical Machine information
For Each objSetting in colSettings
objExcel.Cells(i, j).Value = "Manufacturer:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objSetting.Manufacturer

i = i + 1
j = j - 1

i = i + 1
j = 1

objExcel.Cells(i, j).Value = "Model:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objSetting.Model

i = i + 1
j = j - 1

objExcel.Cells(i, j).Value = "System Type:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = objSetting.SystemType
Next

Set objSetting = nothing

' Autofit the columns
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft


'*************************************************************************************
'Software Information
'*************************************************************************************

'Activate the Software worksheet
objExcel.Worksheets("Software").Activate

i = 1
j = 1

objExcel.Cells(i, j) = "Software"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1

objExcel.Cells(i, j) = "Caption:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Version:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Description:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Vendor:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Identiying Number:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Install Date:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Install Location:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Package Cache:"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

For Each objSoftware in colSoftware
objExcel.Cells(i, j) = objSoftware.Caption

j = j + 1

objExcel.Cells(i, j) = objSoftware.Name

j = j + 1

objExcel.Cells(i, j) = objSoftware.Version

j = j + 1

objExcel.Cells(i, j) = objSoftware.Description

j = j + 1

objExcel.Cells(i, j) = objSoftware.Vendor

j = j + 1

objExcel.Cells(i, j) = objSoftware.IdentifyingNumber

j = j + 1

objExcel.Cells(i, j) = objSoftware.InstallDate2

j = j + 1

objExcel.Cells(i, j) = objSoftware.InstallLocation

j = j + 1

objExcel.Cells(i, j) = objSoftware.PackageCache

j = 1
i = i + 1
Next

Set objSoftware = nothing

i = i + 1
j = 1

'Section header
objExcel.Cells(i, j) = "Installed Hotfixes"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1

'Column headers
objExcel.Cells(i, j) = "Hot Fix ID:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Description:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Installation Date:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Service Pack Level:"
objExcel.Cells(i, j).Font.Bold = TRUE


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

If objQuickFix.HotFixID = "File 1" Then
objExcel.Cells(i, j) = objQuickFix.ServicePackInEffect
Else
objExcel.Cells(i, j) = objQuickFix.HotFixID
End If

j = j + 1

objExcel.Cells(i, j) = objQuickFix.Description

j = j + 1

objExcel.Cells(i, j) = objQuickFix.InstalledBy

j = j + 1

objExcel.Cells(i, j) = objQuickFix.ServicePackInEffect
Next

Set objQuickFix = nothing

' Autofit the columns
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft

'*************************************************************************************
'Services Information
'*************************************************************************************

'Activate the services worksheet
objExcel.Worksheets("Services").Activate

i = 1
j = 1

'Column headers
objExcel.Cells(i, j).Value = "Service"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = "Status"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = "StartMode"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = "StartName"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j).Value = "PathName"
objExcel.Cells(i, j).Font.Bold = TRUE

'Services data
For Each objService in colServices
i = i + 1
objExcel.Cells(i, 1) = objService.Name
objExcel.Cells(i, 2) = objService.State
objExcel.Cells(i, 3) = objService.StartMode
objExcel.Cells(i, 4) = objService.StartName
objExcel.Cells(i, 5) = objService.PathName
if objService.State = "Stopped" then
objExcel.Cells(i, 2).Font.ColorIndex = 3
end if
Next

Set objService = nothing

' Autofit the first column to fit the longest service name
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft

'*****************************************************************************************
'Hardware Section
'*****************************************************************************************

'Activate the hardware worksheet
objExcel.Worksheets("Hardware").Activate

i = 1
j = 1

'Section header
objExcel.Cells(i, j) = "Logical Drives"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column headers
objExcel.Cells(i, j) = "Drive letters:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Volume Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Description:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "File System:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Total Size (GB):"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Free Space (GB):"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Volume Serial Number:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Compressed:"
objExcel.Cells(i, j).Font.Bold = TRUE


i = i + 1
j = 1

'Logical disk data
For each objDisk in colDisks
objExcel.Cells(i, j) = objDisk.DeviceID

j = j + 1

objExcel.Cells(i, j) = objDisk.VolumeName

j = j + 1

objExcel.Cells(i, j) = objDisk.Description

j = j + 1

objExcel.Cells(i, j) = objDisk.FileSystem

j = j + 1

disk_size = objDisk.Size / 1073741824
objExcel.Cells(i, j) = int(disk_size)

j = j + 1

disk_free = objDisk.FreeSpace / 1073741824
objExcel.Cells(i, j) = int(disk_free)

j = j + 1

objExcel.Cells(i, j) = objDisk.VolumeSerialNumber

j = j + 1

objExcel.Cells(i, j) = objDisk.Compressed

j = 1
i = i + 1
Next

Set objDisk = nothing

j = 1
i = i + 1

'Section header
objExcel.Cells(i, j) = "Physical Drives"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column headers
objExcel.Cells(i, j) = "Caption:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Device ID:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Index:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Interface Type:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Manufacturer:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Media Loaded:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Media Type:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Model:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Partitions:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "SCSI Bus:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "SCSI Logical Unit:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "SCSI Port:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "SCSI TargetId:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Sectors Per Track:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Signature:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Size (GB):"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Status:"
objExcel.Cells(i, j).Font.Bold = TRUE

'Physical disk data
For each objDiskDrive in colDiskDrives

i = i + 1
j = 1

objExcel.Cells(i, j) = objDiskDrive.Caption

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.DeviceID

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Index

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.InterfaceType

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Manufacturer

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.MediaLoaded

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.MediaType

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Model

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Partitions

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.SCSIBus

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.SCSILogicalUnit

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.SCSIPort

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.SCSITargetId

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.SectorsPerTrack

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Signature

j = j + 1

diskDrive_size = objDiskDrive.Size / 1073741824
objExcel.Cells(i, j) = int(diskDrive_size)

j = j + 1

objExcel.Cells(i, j) = objDiskDrive.Status

Next

Set objDiskDrive = nothing

'Get SCSI Controller

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "SCSI Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column headers
objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Device ID:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Driver Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "PNP Device ID:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Protocol Supported:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Status Information:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Configuration Manager Error Code:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Configuration Manager User Configuration:"
objExcel.Cells(i, j).Font.Bold = TRUE


'SCSI controller data
For Each objSCSIItem in colSCSIItems
i = i + 1
j = 1

objExcel.Cells(i, j) = objSCSIItem.Name

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.DeviceID

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.DriverName

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.PNPDeviceID

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.ProtocolSupported

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.StatusInfo

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.ConfigManagerErrorCode

j = j + 1

objExcel.Cells(i, j) = objSCSIItem.ConfigManagerUserConfig
Next

Set objSCSIItem = nothing

'Get BIOS information

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "BIOS Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column header
objExcel.Cells(i, j) = "Manufacturer:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Release Date:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Version:"
objExcel.Cells(i, j).Font.Bold = TRUE

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

objExcel.Cells(i, j) = objBIOS.Manufacturer

j = j + 1

objExcel.Cells(i, j) = objBIOS.Name

j = j + 1

objExcel.Cells(i, j) = objBIOS.ReleaseDate

j = j + 1

objExcel.Cells(i, j) = objBIOS.Version
Next

Set objBIOS = nothing

'Get Processor information

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "Processor Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column headers
objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Manufacturer:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Current Clock Speed (MHz):"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "L2 Cache Size (MB):"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Architecture:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Address Width (bits):"
objExcel.Cells(i, j).Font.Bold = TRUE

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

objExcel.Cells(i, j) = objProcItem.Name

j = j + 1

objExcel.Cells(i, j) = objProcItem.Manufacturer

j = j + 1

objExcel.Cells(i, j) = objProcItem.CurrentClockSpeed

j = j + 1

objExcel.Cells(i, j) = objProcItem.L2CacheSize

j = j + 1

objExcel.Cells(i, j) = objProcItem.Architecture

j = j + 1

objExcel.Cells(i, j) = objProcItem.AddressWidth

Next

Set objProcItem = nothing

'Get Memory Information

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "Physical Memory Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column header
objExcel.Cells(i, j) = "Total Physical Memory (MB):"
objExcel.Cells(i, j).Font.Bold = TRUE

'Physical memory data
For Each objSetting in colSettings
i = i + 1
j = 1

phys_ram = objSetting.TotalPhysicalMemory / 1048576
objExcel.Cells(i, j) = int(phys_ram)
Next

Set objSetting = nothing

'Get Video Information

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "Video Card Information"
objExcel.Cells(i, j).Font.Bold = TRUE

i = i + 1
j = 1

'Column header
objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Description:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Driver Version:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Video Memory (MB):"
objExcel.Cells(i, j).Font.Bold = TRUE

'Video card data
For Each objVideo in colVideo
i = i + 1
j = 1

objExcel.Cells(i, j) = objVideo.Caption

j = j + 1

objExcel.Cells(i, j) = objVideo.Description

j = j + 1

objExcel.Cells(i, j) = objVideo.DriverVersion

j = j + 1

video_ram = objVideo.AdapterRAM / 1048576
objExcel.Cells(i, j) = int(video_ram)

Next

Set objVideo = nothing

'Get Network Adapter Information

j = 1
i = i + 2

'Section header
objExcel.Cells(i, j) = "NIC Information"
objExcel.Cells(i, j).Font.Bold = TRUE

'Column header
i = i + 1
j = 1

objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "MAC Address:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Manufacturer:"
objExcel.Cells(i, j).Font.Bold = TRUE

'Network card data
For Each objNet in colNet

If objNet.MACAddress <> "" Then
i = i + 1
j = 1

objExcel.Cells(i, j) = objNet.Name

j = j + 1

objExcel.Cells(i, j) = objNet.MACAddress

j = j + 1

objExcel.Cells(i, j) = objNet.Manufacturer
End if
Next

Set objNet = nothing

' Autofit the first column to fit the longest name
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft

'******************************************************************************************
'Printers Section
'******************************************************************************************

objExcel.Worksheets("Printers").Activate

i = 1
j = 1

'Section header
objExcel.Cells(i, j) = "Printer Information"
objExcel.Cells(i, j).Font.Bold = TRUE

'Column Headers
i = i + 1
j = 1

objExcel.Cells(i, j) = "Default:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Server Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Share Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Driver Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

j = j + 1

objExcel.Cells(i, j) = "Port Name:"
objExcel.Cells(i, j).Font.Bold = TRUE

'List printer objects
For Each objPrintItem in colPrintItems
i = i + 1
j = 1

objExcel.Cells(i, j) = objPrintItem.Default

j = j + 1

objExcel.Cells(i, j) = objPrintItem.Name

j = j + 1

objExcel.Cells(i, j) = objPrintItem.ServerName

j = j + 1

objExcel.Cells(i, j) = objPrintItem.ShareName

j = j + 1

objExcel.Cells(i, j) = objPrintItem.DriverName

j = j + 1

objExcel.Cells(i, j) = objPrintItem.PortName
Next

Set objPrintItem = nothing

' Autofit the first column to fit the longest name
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft

'Activate the Main worksheet
objExcel.Worksheets(strComputer).Activate

'Cleanup objects
Set objExcel.Quit
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
wscript.echo("Finished")

Wscript.Quit 0

No comments: