Windows and mount points…

Those of us who used CP/M and DOS in the early days became accustomed to drive letters which BTW was a good design when most systems has two maybe three devices. The same computer enthusiasts who used CP/M and DOS most likely through education or professional experience were introduced to UNIX at some point. If you are like me this was probably during your college years, we began to realize how much more elegant the UNIX operating system was with novel ideas such as “mount points”, well Microsoft sorta figured this out a few years ago and integrated mount points into Windows. To me there is absolutely no reason that anyone in the server space should be using drive letters (Excluding A:,B:,C: and D: of course) unless legacy applications are hard coded to use drive letters and the move to mount points is just too painful (unfortunately in the past drive letters were the only way to address storage devices, if you are still doing this for new applications shame, shame!). One issue with mount points is an inability to easily determine total, used, and free space for a physical device from Windows Explorer. While I use mount points almost exclusively, many of my customers complain of the need to drop to the CLI (only a complaint you would hear in the Windows world…. although I agree it is nice to have a single view of all physical devices, like that provided by Windows Explorer). They could open Disk Management but that too is kind of cumbersome to just view available space. Here is a small VB script that I wrote that will provide total, used and free space for physical devices by enumerating the devices that match a specific drive label:

——— SCRIPT STARTS HERE ———

WScript.Echo “B2D Capactiy Reporter – ” & Date
Wscript.Echo “RJB – 1/2/2008”
Wscript.Echo “———————————–”
Wscript.Echo “———————————–”

Dim totalB2D, totalUSED, totalFREE
totalB2D = 0
totalUSED = 0
totalFREE = 0

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colItems = objWMIService.ExecQuery(“Select * from Win32_Volume where label like ‘b2d%‘”)

For Each objItem In colItems
WScript.Echo “Label: ” & objItem.Label
WScript.Echo “Mount Point: ” & objItem.Name
WScript.Echo “Block Size: ” & (objItem.BlockSize / 1024) & “K”
WScript.Echo “File System: ” & objItem.FileSystem
WScript.Echo “Capacity: ” & round(objItem.Capacity / 1048576 / 1024,2) & ” GB”
WScript.Echo “Used Space: ” & round((objItem.Capacity – objItem.FreeSpace) / 1048576 / 1024,2) & ” GB”
WScript.Echo “Free Space: ” & round(objItem.FreeSpace / 1048576 / 1024,2) & ” GB”
WScript.Echo “Percent Free: ” & round(objItem.FreeSpace / objItem.Capacity,2) * 100 & ” %”
totalB2D = totalB2D + (objItem.Capacity / 1048576 / 1024)
totalFREE = totalFREE + (objItem.FreeSpace / 1048576 / 1024)
totalUSED = totalUSED + ((objItem.Capacity – objItem.FreeSpace)/ 1048576 / 1024)
Wscript.Echo “———————————–”
Next

WScript.Echo “———————————–”
WScript.Echo “Total B2D Capacity: ” & round(totalB2D / 1024,2) & ” TB”
WScript.Echo “Total Used Capacity: ” & round(totalUSED / 1024,2) & ” TB”
WScript.Echo “Total Free Capacity: ” & round(totalFREE / 1024,2) & ” TB”
WScript.Echo “Total Percent Free: ” & round(totalFREE / totalB2D,2) * 100 & ” %”

——— SCRIPT ENDS HERE ———

This script was originally written to report the utilization of devices that were being used as Backup-to-Disk targets, hence the name B2D Capacity Reporter. The scripts keys on the disk label so it is important to label the disks properly so that it will report accurately (this can be done from Disk Management or the Command line). I have bolded above the only change that really needs to be made to make the script function properly. This script could easily be modified to report across multiple systems which could be useful if you are looking to tally all the space across multiple servers.

I have only tested this on Windows 2003 so I am not sure how it will function on other versions of Windows. Enjoy!

Oh, one more thing. When you save the script be sure to run it with cscript not wscript (e.g. – cscript diskspace.vbs).

4 thoughts on “Windows and mount points…

  1. Thanks for the script! This also works on WIndows 2008 EE. I am
    running it hourly and keeping for 30 days in SQL Server
    2008, then using Reporting Services email subscriptions each
    morning to monitor trends.

    I rearranged your script to create a suitable flat file. I loop
    twice to check both nodes of a failover cluster.

    ——— SCRIPT STARTS HERE ——— WScript.Echo
    “TimeStamp|Server|Label|Mount_Point|Block_Size_K|File_System|Capacity_GB|Used_Space_GB|Free_Space_GB|Percent_Free”

    strComputer = “GAALPA1TOOLSDB1” Set objWMIService =
    GetObject(“winmgmts:” _ &
    “{impersonationLevel=impersonate}!\\” & strComputer &
    “\root\cimv2”) Set colItems = objWMIService.ExecQuery(“Select *
    from Win32_Volume where label like ‘Pans%'”) For Each objItem In
    colItems WScript.Echo Date & ” ” & Time & “|” _ &
    strComputer & “|” _ & objItem.Label & “|” _ &
    objItem.Name & “|” _ & (objItem.BlockSize / 1024) &
    “|” _ & objItem.FileSystem & “|” _ &
    round(objItem.Capacity / 1048576 / 1024,2) & “|” _ &
    round((objItem.Capacity – objItem.FreeSpace) / 1048576 / 1024,2)
    & “|” _ & round(objItem.FreeSpace / 1048576 /
    1024,2)  & “|” _ & round(objItem.FreeSpace /
    objItem.Capacity,2) * 100 Next

    strComputer = “GAALPA1TOOLSDB2” Set objWMIService =
    GetObject(“winmgmts:” _ &
    “{impersonationLevel=impersonate}!\\” & strComputer &
    “\root\cimv2”) Set colItems = objWMIService.ExecQuery(“Select *
    from Win32_Volume where label like ‘Pans%'”) For Each objItem In
    colItems WScript.Echo Date & ” ” & Time & “|” _ &
    strComputer & “|” _ & objItem.Label & “|” _ &
    objItem.Name & “|” _ & (objItem.BlockSize / 1024) &
    “|” _ & objItem.FileSystem & “|” _ &
    round(objItem.Capacity / 1048576 / 1024,2) & “|” _ &
    round((objItem.Capacity – objItem.FreeSpace) / 1048576 / 1024,2)
    & “|” _ & round(objItem.FreeSpace / 1048576 /
    1024,2)  & “|” _ & round(objItem.FreeSpace /
    objItem.Capacity,2) * 100 Next——— SCRIPT ENDS HERE
    ———

Leave a Reply to Bill Cancel reply

Your email address will not be published. Required fields are marked *