Answered Disk Space Script

  • Tuesday, May 15, 2012 1:35 PM
     
     

    I have the following script that reports on disk space

    sstrComputer = "File01"
    Summary = 0

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 


    Set colLogicalDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk where DriveType = '3'")

    For Each Driveletter in colLogicalDisks 
                    DriveSize = Driveletter.size / 1073741824
                    DriveSize = Round(DriveSize,2)
                    DriveSpace = Driveletter.FreeSpace / 1073741824
                    DriveSpace = Round(DriveSpace,2)
                    DrivePercent = DriveSpace  / DriveSize 
                    DrivePercent = DrivePercent * 100 
                    DrivePercent = Round(DrivePercent,1)
                    Wscript.Echo strComputer & " " & Driveletter.Name & " size: " & DriveSize & " GB" & " free space: " & DriveSpace & " GB" & " percent free space: " & DrivePercent & " %" 


    Next

    window PS cscript and cmd outputs the following results when run as vbscript

    File01 C: size: 15.01 GB free space: 6.29 GB percent free space: 41.9 %

    I would like to output the data into table as follow

    Computer   Driveletter    Size     free Space percent free space

    File01 C: 15.01GB 6.29GB 41.9%

    What do I do to the script or is this not possible?

    Is there an easier way?

All Replies

  • Tuesday, May 15, 2012 1:52 PM
    Moderator
     
     Proposed Answer Has Code

    Yes, there's an easier way. Use PowerShell.

    get-wmiobject Win32_LogicalDisk -filter "DriveType=3"

    Bill

  • Tuesday, May 15, 2012 2:14 PM
     
      Has Code
    Thanks for your reply, PowerShell  get-wmiobject Win32_LogicalDisk -filter "DriveType=3"

    is good for one machine. I need to query about 10machines and display the results

    in a table.

    How do I use PowerShell to achieve this ?

  • Tuesday, May 15, 2012 2:21 PM
    Moderator
     
     

    Hi,

    This question has already been asked and answered. See this thread:

    http://social.technet.microsoft.com/Forums/en/ITCG/thread/a9967b7f-8001-4ec2-b01d-54b72686f645

    Bill

  • Wednesday, May 16, 2012 11:20 AM
     
     

    Hi,

    Looks like the data i placed in the question was incorrectly presented. What I am trying to achive the data from the query being output into a table with the following columns - Computer Driveletter, Size, freeSpace and percent free space.

    Computer   Driveletter   Size     free Space percent free space 

    File01 C:       15.01GB 6.29GB       41.9%

    My script provides the results, it's just the presentation of the results that I would like to amend.

    Thanks,


  • Wednesday, May 16, 2012 12:35 PM
    Moderator
     
     Answered

    The reformatting of the output seems to me to be almost trivial, because I know a bit about VBS.  Therefore, I must assume you know nothing at all.   Please don't think I am mocking or scolding you.  That is not my intention.  It is just that I have found that not only is it hard to tell someone with no knowledge of the subject how to modify an artifact that is not understood, but it is also my observation that it can be counter productive to just present a modified version.   Rather, it can be more instructive to get the questioner to answer the right questions for themselves.  Then they begin to understand something about the subject matter and are able to apply that knowledge to later problems.

    So, I ask you a question: "What line or lines do you think needs to be added or modified?"  My second question is: "If you don't have any idea about the first question, where do you propose to find an answer (besides asking someone here to do the work for you)?"

    Hints:  You want a new header line that is not currently provided by the existing script.  What script statement is used to output text to the console/screen?  If you don't know, look at the WScript documentation, a downloadable version is available here.

    I really hope that helps,


    Tom Lavedas