Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System info script

Status
Not open for further replies.

tltechie

Technical User
Apr 25, 2011
17
US
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
 
Try changing:
Code:
Do while not isempty([COLOR=red]objExcel[/color].Cells(loopCount, 1).Value)
to:
Code:
Do while not isempty([COLOR=blue]workbook[/color].Cells(loopCount, 1).Value)
 
that didnt work, it just got it stuck in an endless loop
 
Take the OERN out to see what errors may occur. If any, they will give you a pretty good idea of what's not going on.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Suggestion. You've created an objFSO object. Why not use it?

Code:
'Gets the directory where our script is running from
directory = [red]CreateObject("Scripting.FileSystemObject")[/red].GetParentFolderName(Wscript.ScriptFullName)

Also, instead of NOT isEmpty(), use a regular operator. objExcel.Cells(loopCount, 1).value is the machine name, right (thus, a string)? isEmpty() can return false positives if you're not looking for nulls.

Code:
Do while (objExcel.Cells(loopCount, 1).Value <> "")

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top