Working on creating a script that will pull system information from machines on a network. The machine names are listed in an excel file and should pull them in a loop. I had the code in 2 sections origionally, the Loop and the Information gathering, but when i combine them the output.txt file is no longer created. Anyone help me out seeing what i messed up?
option explicit
On Error Resume Next
Dim loopCount, directory, objExcel, workbook
Dim objFileSystem, objOutputFile
Dim strOutputFile
Dim size, size1
Set objExcel = CreateObject("Excel.Application")
' generate a filename base on the script name
strOutputFile = "c:\output.txt"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
ForAppending = 8
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, ForAppending, True)
Const CONVERSION_FACTOR = 1048576
Const WARNING_THRESHOLD = 500
'Gets the directory where our script is running from
directory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName)
'Open our XLS file
Set workbook = objExcel.Workbooks.Open(directory & "\test2.xls")
'We want to skip the header row, and then the blank row below
loopCount = 1
Do while not isempty(objExcel.Cells(loopCount, 1).Value)
Dim i 'For looping through the columns on each row
Dim RemoteMachine 'Value extracted from each cell
'Spreadsheet is 6 columns across
For i = 1 To 1
RemoteMachine = objExcel.Cells(loopCount, i).Value
Set objWMIService = GetObject("winmgmts:\\" & RemoteMachine)
Set objLocaldrive = objWMIService.Get ("Win32_LogicalDisk.DeviceID='c:'")
FreeMegaBytes = objLocaldrive.Freespace / CONVERSION_FACTOR
Set objLocaldrive = objWMIService.Get ("Win32_LogicalDisk.DeviceID='D:'")
FreeMegaBytes1 = objLocaldrive.Freespace / CONVERSION_FACTOR
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set CommandLine = CreateObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objSWbemServices = GetObject("winmgmts:\\" & RemoteMachine)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")
For Each objSWbemObject in colSWbemObjectSet
objOutputFile.WriteLine RemoteMachine & VbCrLf & "Hard Drive Space" & VbCrLf & _
"Megabytes of Free Disk Space on c:\ " & Int(FreeMegaBytes) & VbCrLf & _
"Megabytes of Free Disk Space on D:\ " & Int(FreeMegaBytes1) & VBCrLF & VBCrLF
next
WScript.Echo "MACHINE NAME: " & RemoteMachine
Next
loopCount = loopCount + 1
Loop
objOutputFile.Close
Set objFileSystem = Nothing
objExcel.Workbooks.Close
objExcel.quit
objExcel = Empty
workbook = Empty
option explicit
On Error Resume Next
Dim loopCount, directory, objExcel, workbook
Dim objFileSystem, objOutputFile
Dim strOutputFile
Dim size, size1
Set objExcel = CreateObject("Excel.Application")
' generate a filename base on the script name
strOutputFile = "c:\output.txt"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
ForAppending = 8
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, ForAppending, True)
Const CONVERSION_FACTOR = 1048576
Const WARNING_THRESHOLD = 500
'Gets the directory where our script is running from
directory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName)
'Open our XLS file
Set workbook = objExcel.Workbooks.Open(directory & "\test2.xls")
'We want to skip the header row, and then the blank row below
loopCount = 1
Do while not isempty(objExcel.Cells(loopCount, 1).Value)
Dim i 'For looping through the columns on each row
Dim RemoteMachine 'Value extracted from each cell
'Spreadsheet is 6 columns across
For i = 1 To 1
RemoteMachine = objExcel.Cells(loopCount, i).Value
Set objWMIService = GetObject("winmgmts:\\" & RemoteMachine)
Set objLocaldrive = objWMIService.Get ("Win32_LogicalDisk.DeviceID='c:'")
FreeMegaBytes = objLocaldrive.Freespace / CONVERSION_FACTOR
Set objLocaldrive = objWMIService.Get ("Win32_LogicalDisk.DeviceID='D:'")
FreeMegaBytes1 = objLocaldrive.Freespace / CONVERSION_FACTOR
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set CommandLine = CreateObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objSWbemServices = GetObject("winmgmts:\\" & RemoteMachine)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")
For Each objSWbemObject in colSWbemObjectSet
objOutputFile.WriteLine RemoteMachine & VbCrLf & "Hard Drive Space" & VbCrLf & _
"Megabytes of Free Disk Space on c:\ " & Int(FreeMegaBytes) & VbCrLf & _
"Megabytes of Free Disk Space on D:\ " & Int(FreeMegaBytes1) & VBCrLF & VBCrLF
next
WScript.Echo "MACHINE NAME: " & RemoteMachine
Next
loopCount = loopCount + 1
Loop
objOutputFile.Close
Set objFileSystem = Nothing
objExcel.Workbooks.Close
objExcel.quit
objExcel = Empty
workbook = Empty