locked
WMI-call to check free diskspace RRS feed

  • Question

  • Ok, this may be very trivial, but I have been looking for a few hours now on how to do it and have been unable to find out how..

    I want to, using the command-line (wmic), make a simple batchfile that queries my WHS and returns the free diskspace in megabytes (or kilobytes or whatever)

    I have found vbscript-example on how to do WMI-requests, but I don't know what to ask for...

    [edit]
    Ok, after some digging I have found that I can make a call to Win32_LogicalDisk.FreeSpace, that gets me halfway there, the problem is that it only return free space on drives with driveletters....


    Monday, December 31, 2007 11:38 AM

All replies

  • Hm, yeah, managed to work it out on myself, so I thought I'd post the code here:

    strComputer = "."
    Summary = 0

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

    Set colDisks = objWMIService.ExecQuery ("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk where Name = '_Total'")

    For Each Driveletter in colDisks
        Summary = Summary + Driveletter.FreeMegabytes
    Next

    Summary = Summary / 1024
    Summary = Round(Summary)

    Wscript.Echo "Free space: " & Summary & " GB"
    Monday, December 31, 2007 2:37 PM