JustScriptIt
Technical User
I modified code such that, it will bypass IP addresses it cannot make WMI connection to.
However, there is one IP address which causes the program to throw an error
Whether it is several IP addresses, or that one particular IP address in the list, it causes the error on line 65
And line 65 is
Below is entire code:
However, there is one IP address which causes the program to throw an error
Whether it is several IP addresses, or that one particular IP address in the list, it causes the error on line 65
Code:
free_disk_space_csv.vbs(65, 4) (null): 0x80041010
And line 65 is
Code:
For Each objItem in colItems
Below is entire code:
Code:
Option Explicit
Dim objInputFSO, objOutputFSO, objFile, objErrorOutputFSO, objErrorFile
Dim strInputFile, strData, arrLines, strLine
Dim objWMISvc, colItems, objItem, strComputerDomain, strMember
Dim strDriveType, strDiskSize
Dim strComputer, strKeyPath, strValueName, oReg, strValue, dwValue
Dim objLogicalDisk, strCfree, strDfree, strHDfree
Dim strName, strVersion, intComm, strGroup, strPolicy, strHardware, strVirus, strIPS, intNTP, strSEPM
Dim strArray
Dim bErrorFound
const ForAppending = 8
const strOutputFile = "output_for_free_disk_space.csv"
const strErrOutputFile = "error_output_for_free_disk_space.csv"
'Create an Input File System Object
Set objInputFSO = CreateObject("Scripting.FileSystemObject")
'Name of the input text file
strInputFile = InputBox("What is the name of file with list of computers?")
'Open the text file - strData now contains the whole file
strData = objInputFSO.OpenTextFile(strInputFile,1).ReadAll
'Split the text file into lines
arrLines = Split(strData,vbCrLf)
'Create an Output File System Object
Set objOutputFSO = CreateObject("Scripting.FileSystemObject")
'Create Output File
Set objFile = objOutputFSO.CreateTextFile(strOutputFile)
'Create an Output File System Object for Recording Error
Set objErrorOutputFSO = CreateObject("Scripting.FileSystemObject")
'Create Output File
Set objErrorFile = objOutputFSO.CreateTextFile(strErrOutputFile)
objFile.WriteLine("IP Address,Computer,Drive Letter,Drive Type, Disk Size, Free Space")
'Step through the lines
For Each strLine in arrLines
strComputer = strLine
bErrorFound = False
' Can we connect to \root\cimv2 namespace?
On Error Resume Next
Set objWMISvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If (Err.Number <> 0) Then
objErrorFile.WriteLine(strComputer & " is unreachable")
bErrorFound = True
End If
On Error Goto 0
If bErrorFound = False Then
Set colItems = objWMISvc.ExecQuery("Select * from Win32_LogicalDisk")
For Each objItem in colItems
Select Case objItem.DriveType
Case 1 strDriveType = "Drive could not be determined."
Case 2 strDriveType = "Removable Drive"
Case 3 strDriveType = "Local hard disk."
Case 4 strDriveType = "Network disk."
Case 5 strDriveType = "Compact disk (CD)"
Case 6 strDriveType = "RAM disk."
Case Else strDriveType = "Drive type Problem."
End Select
If objItem.DriveType =2 Then
strDiskSize = Int(objItem.Size /1048576) & " Mega Bytes"
Else
strDiskSize = Int(objItem.Size /1073741824) & " GB"
End If
objFile.WriteLine(strComputer & "," & objItem.SystemName & "," & objItem.Name & "," & strDriveType & _
"," & strDiskSize & "," & Int(objItem.FreeSpace /1073741824) & " GB")
Next
objFile.WriteLine("")
End If
Next
Wscript.echo "Output is located at output_for_free_disk_space.csv"
'Cleanup
Set objInputFSO=Nothing
Set objOutputFSO=Nothing