General discussion

Locked

Diskspace VBScript Help needed

By keebmachine ·
How do I edit this script so that it will output the diskspace for each computer?

To run the script the syntax is

cscript diskspace.vbs computername

Here is the code:

On Error Resume Next
Const CONVERSION_FACTOR = 1048576
Const WARNING_THRESHOLD = 100

If WScript.Arguments.Count = 0 Then
Wscript.Echo "Usage: FirstScript.vbs server1 [server2] [server3] ..."
WScript.Quit
End If

For Each Computer In WScript.Arguments
Set objWMIService = GetObject("winmgmts://" & Computer)
If Err.Number <> 0 Then
Wscript.Echo Computer & " " & Err.Description
Err.Clear
Else
Set colLogicalDisk = _
objWMIService.InstancesOf("Win32_LogicalDisk")
For Each objLogicalDisk In colLogicalDisk
FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR
If FreeMegaBytes < WARNING_THRESHOLD Then
Wscript.Echo Computer & " " & objLogicalDisk.DeviceID & _
" is low on disk space."
End If
Next
End If
Next

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by SparkieIT In reply to Diskspace VBScript Help n ...

Are you working off a list of known computers or are you looking for any possible computers?

If you have a text file or list you could use something like this... (Running: cscript diskspace.vbs c:\listofcomputernames.txt)

Dim objFile, objGroup, objFSO, strFile
Dim strComputer, intCount

strFile = Wscript.Arguments(0)

Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFile = objFSO.OpenTextFile(strFile, 1)
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Unable to open file " & strFile
Set objFSO = Nothing
Wscript.Quit(1)
End If

intCount = 0
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
If strNTName <> "" Then
Set objWMIService = GetObject("winmgmts://" & strComputer)
If Err.Number <> 0 Then
Wscript.Echo strComputer & " " & Err.Description
Err.Clear
Else
Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
For Each objLogicalDisk In colLogicalDisk
FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR
If FreeMegaBytes < WARNING_THRESHOLD Then
Wscript.Echo Computer & " " & objLogicalDisk.DeviceID & " is low on disk space."
End If
Next
End If

End If
Loop


Hope that helps...

Collapse -

by keebmachine In reply to

Poster rated this answer.

Collapse -

by keebmachine In reply to Diskspace VBScript Help n ...

I receive an error when I attempt to use this script. (4, 1) Microsoft VBScript runtime error: Subscript out of range.

Heck it is Christmas! Enjoy your 200 Points!

I have found this script on the web that I am using instead. I like this script because of the way it formats the text.

Here is a link to the script.

http://www.robvanderwoude.com/files/freespace_vbs.txt

Collapse -

by keebmachine In reply to Diskspace VBScript Help n ...

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Forums