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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With An Array 1

Status
Not open for further replies.

Brycspain

IS-IT--Management
Mar 9, 2006
150
US
I'm trying to write a disk collection to a text file using WMI and I seem to be missing an object somewhere. I looked up the error code ive been getting (800A01A8 oject required: '0') and can't seem to figure out where I'm going wrong. IVe bolded the line I'm getting the error on.

I tried to use error checking on the array itself and after each writeline. Any help would be appreciated thanks.

Code:
Option Explicit

'declare the constants
Const ForReading = 1
Const ForAppending = 8
Const sLogFileName = "c:\scripts\log.txt"
Const sServerFileName = "c:\scripts\servers.txt"
Const HARD_DISK = 3

'turn off error checking
'On Error Resume Next

'dim the variables
Dim objDictionary, objFSO, objOU, objComputer, strComputer
Dim colHardDrives, objWMIService, colItems, objHardDrive
Dim i, objItem, sName, objTextFile, strNextLine, oLogFile

'setup dictionary object for the server array
Set objDictionary = CreateObject("Scripting.Dictionary")

'setup file system object to work with text files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(sServerFileName, ForReading)
i = 0

'run through test file until all servers are placed in array
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop



'open new text file to log events during the script
Set oLogFile = objFSO.OpenTextFile(sLogFileName, ForAppending)

'start running through each server in the array
For Each objItem in objDictionary
	strComputer = objDictionary.Item(objItem)
	If TestPing(strComputer) = False Then
		oLogFile.WriteLine Now() & " Couldn't reach " & strComputer & VbCrLf
	Else
		oLogFile.WriteLine Now() & " Able to ping " & strComputer & VbCrLf
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
	    Set colHardDrives = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk where Drivetype = " _
	                                           & HARD_DISK & "") 
		For Each objHardDrive In colHardDrives
		[B]oLogFile.Writeline "DeviceID: " & objItem.DeviceID[/B]
	    oLogFile.Writeline "FreeSpace: " & objItem.FreeSpace\1024\1024/1024+1 & " GB"
	    Next
	End If  
Next

'close the server text file after it's finished reading
objTextFile.close

'close the log file
oLogFile.Writeline ""
oLogFile.Close
WScript.echo "Script Finished"

'function to ping computers
Function TestPing(sName)
   TestPing = False
   If sName = "" Then
       WScript.Echo "Bad computer name string!"
   Else
       Dim cPingResults, oPingResult
       Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & sName & "'")       
       For Each oPingResult In cPingResults      
           If oPingResult.StatusCode = 0 Then
               TestPing = True
           End If
       Next
   End If
End Function
 
Perhaps this ?
oLogFile.Writeline "DeviceID: " & objHardDrive.DeviceID

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That's too easy PHV...I looked at that code 20 times and didn't see that error.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top