Pages

Showing posts with label vbscript to check free disk space. Show all posts
Showing posts with label vbscript to check free disk space. Show all posts

Friday 15 June 2012

Check Free Disk Space - VBScript


strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'",,48) 
For Each objItem in colItems 
    Bytes = objItem.FreeSpace


If Bytes >= 1073741824 Then
SetBytes = Round(FormatNumber(Bytes / 1024 / 1024 / 1024, 2), 0) & " GB"
ElseIf Bytes >= 1048576 Then
SetBytes = Round(FormatNumber(Bytes / 1024 / 1024, 2), 0) & " MB"
ElseIf Bytes >= 1024 Then
SetBytes = Round(FormatNumber(Bytes / 1024, 2), 0) & " KB"
ElseIf Bytes < 1024 Then
SetBytes = Bytes & " Bytes"
Else
SetBytes = "0 Bytes"
End If


Wscript.Echo "OUTPUT = " & SetBytes


Next

Tuesday 30 August 2011

VBScript to Check Free Disk Space

Following script helps to find free disk space available on C-Drive, change the Drive letter in the script if you want to find free disk space of any other drive.


strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'",,48) 
For Each objItem in colItems 
    Bytes = objItem.FreeSpace

If Bytes >= 1073741824 Then
	SetBytes = Round(FormatNumber(Bytes / 1024 / 1024 / 1024, 2), 0) & " GB"
ElseIf Bytes >= 1048576 Then
	SetBytes = Round(FormatNumber(Bytes / 1024 / 1024, 2), 0) & " MB"
ElseIf Bytes >= 1024 Then
	SetBytes = Round(FormatNumber(Bytes / 1024, 2), 0) & " KB"
ElseIf Bytes < 1024 Then
	SetBytes = Bytes & " Bytes"
Else
	SetBytes = "0 Bytes"
End If

Wscript.Echo "OUTPUT = " & SetBytes

Next