VBScript - Trouble with Excel output

Hi All, I'm having some trouble with a VBScript that stops output after the first 2 lines for each host specified in "computers.txt".

Any help is greatly appreciated!

Here's the script:

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 = "	Hardware Name  " 
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 = "	Hardware Manufacturer  " 
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 = " Operating System "
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("D1") 
objRange.Activate 
Set objRange = ObjExcel.ActiveCell.EntireColumn 
objRange.AutoFit()

objExcel.Cells(1, 5).Value = "	Hardware Description  " 
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("E1") 
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(".\Computers.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 colHardware = objWMIService.ExecQuery("Select * from Win32_PnPEntity")

If Err.Number = 0 Then 
	For Each objComputer In colSettings 
		
		For Each objOS In colOSSettings
		
			strOS = objOS.Caption
							 
	For Each objHardware In colHardware
		
		strHardwareName = objHardware.Name
		strHardwareManufacturer = objHardware.Manufacturer
		strHardwareCaption = objHardware.Caption

		If computerName <> oldName Then 
		  objExcel.Cells(y, 1).Value = computerName 
		  objExcel.Cells(y, 1).Alignment = "Center" 
		  objExcel.Cells(y, 2).Value = strHardwareName 
		  objExcel.Cells(y, 2).Alignment = "Center" 
		  objExcel.Cells(y, 3).Value = strHardwareManufacturer
		  objExcel.Cells(y, 3).Alignment = "Center"	 
		  objExcel.Cells(y, 4).Value = strOS 
		  objExcel.Cells(y, 4).Alignment = "Center" 
		  objExcel.Cells(y, 5).Value = strHardwareCaption 
		  objExcel.Cells(y, 5).Alignment = "Center"
					
		  oldName = computerName 
		  y = y + 1 
		End If 
	   computerName = "" 
	   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.Range("E1") 
objRange.Activate 
Set objRange = objExcel.ActiveCell.EntireColumn 
objRange.Autofit() 

Posted Jun 23, 2015, 9:26 PM UTC · edited

10

No comments yet

Nobody commented on this post, or the comments weren't captured.