VBSCRIPT To find the free space and total space of a group of system


 


 This script will read the INPUT file from the loacation and will find out the free space and total space of teh drives in the system and store it in OUTPUT.txt file.


The Input file should be having the server names one servername per line (line delimted).


Copy the file and save it as .vbs file and excute it after making sure that the INPUT.txt file is there. Also these servers needs to be reachable adn WMI should be avilable remotely. In short you should be having admin rights 🙂


==================================================================


Option Explicit


const strReport = "c:\OUTPUT.txt"
const sFile = "C:\INPUT.txt"


Dim objWMIService, objItem, colItems
Dim strDriveType, strDiskSize, txt


Dim oFSO, oFile, sText,strComputer
Set oFSO = CreateObject("Scripting.FileSystemObject")


Dim objFSO,objTextFile
Set objFSO = createobject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(strReport)



If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
 Do While Not oFile.AtEndOfStream
  sText = oFile.ReadLine
   If Trim(sText) <> "" Then
          strComputer=sText
              Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
              Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType=3")
             txt = sText & vbtab & "Drive" & vbtab & "Size" & vbtab & "Used" & vbtab & "Free" & vbtab & "Free(%)" & vbcrlf
        For Each objItem in colItems
 
             DIM pctFreeSpace,strFreeSpace,strusedSpace
 
             pctFreeSpace = INT((objItem.FreeSpace / objItem.Size) * 1000)/10
       strDiskSize = Int(objItem.Size /1073741824) & "Gb"
       strFreeSpace = Int(objItem.FreeSpace /1073741824) & "Gb"
       strUsedSpace = Int((objItem.Size-objItem.FreeSpace)/1073741824) & "Gb"
       txt = txt & vbtab & vbtab & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf


        Next
     
     
     objTextFile.Write(txt)
     
     
     
  
 End If
 Loop
 objTextFile.Close
oFile.Close
Else
WScript.Echo "The file was not there."
End If


=======================================================


Hope tha this information will be helpful


Sudheesh Narayanaswamy 


 

Comments (14)

  1. kalam says:

    Can some please lemme know how add one free line after every result of a server/ system.

  2. Senna says:

    Good script but it is not retrieving all volumes how can i do this (example volumes mounted ones sql)

  3. Rakesh says:

    Hi, When I tried for systems in other domains I am getting, error msg : the remote server does not exist or unavailable,

  4. Rakesh says:

    Hi I am getting, error msg : the remote server does not exist or unavailable

  5. Prerna says:

    if i want to check space folder of particular path then how to check that?

  6. Ganesh D says:

    Hi, its not working properly could you please send the correct script

  7. Rocky says:

    Its really a good script using it with few more addition thnx

  8. arun says:

    can u please add the script to find the file size with the extension format. ( .docx size ..xlsx size etc)

  9. arun says:

    this script is really helpful to find disk space in servers…..

  10. vijay says:

    Hi Sudheer,

    Your Vbscript to check the diskspace across the network is more usefull to me,i need some extra info to support the above script to generate daily mail to the common mail box with all disk space information.

    Please respond to my request.

    Thanks
    Vijayk

  11. Satheesh Thayal says:

    But still if the server name on INPUT.txt is invalid the script ends with “The remote ser
    ver machine does not exist or is unavailable: ‘GetObject”…

  12. Sudheesh N says:

    Thank You i had made the changes too in the script now

  13. Anonymous says:

    First of all thank you!

    In order to line up the drive measurements to the columns, I had to add another "vbtab" like so:

    txt = txt & vbtab & vbtab & objItem.Name & vbtab & strDiskSize & vbtab & strUsedSpace & vbTab & strFreeSpace & vbtab & pctFreeSpace & vbcrlf

Skip to main content