If I list multiple computers in the array and one of them doesn't exist then the whole script fails, what I would like to happen is for a message to appear saying that the server is offline and then going onto the next server.
Here is the script.
*************************************
*************************************
'
'This script will find the physical drives on a PC and work out the Total Size, Free Space & Percentage of Free Space
'How to run: cscript.exe disks.vbs > disks.txt
'
Wscript.Echo("Date: ")
Wscript.Echo(FormatDateTime(Date()))
Const HARD_DISK = 3
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
Wscript.Echo "Drive Letter"& vbTab & vbTab & objDisk.DeviceID
Wscript.Echo "Total Disk Size"& vbTab & vbTab & FormatNumber(intTotalSpace / 1073741824 ,3)
Wscript.Echo "Free Space"& vbTab & vbTab & Formatnumber(objDisk.Freespace / 1073741824 ,3)
Wscript.Echo "Percentage Free Space"& vbTab & FormatPercent(pctFreeSpace)
Wscript.Echo
Next
Next
Here is the script.
*************************************
*************************************
'
'This script will find the physical drives on a PC and work out the Total Size, Free Space & Percentage of Free Space
'How to run: cscript.exe disks.vbs > disks.txt
'
Wscript.Echo("Date: ")
Wscript.Echo(FormatDateTime(Date()))
Const HARD_DISK = 3
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
Wscript.Echo "Drive Letter"& vbTab & vbTab & objDisk.DeviceID
Wscript.Echo "Total Disk Size"& vbTab & vbTab & FormatNumber(intTotalSpace / 1073741824 ,3)
Wscript.Echo "Free Space"& vbTab & vbTab & Formatnumber(objDisk.Freespace / 1073741824 ,3)
Wscript.Echo "Percentage Free Space"& vbTab & FormatPercent(pctFreeSpace)
Wscript.Echo
Next
Next