Get Physical Drive from Logical Drive

Posted on 2009-04-21
Last Modified: 2012-05-06
I am writing a script to take an inventory of all servers, and all aspects of all servers.  I am using the WMI service to poll Win32_LogicalDisk for the label (C:), type of drive (Local/network/removeable), total and free space.  I'd like to also associate a logical drive to the physical drive it is located on. (based on Win32_DiskDrive)  I'm looking for help with at least the psuedo-code to associate the logical to physical.  I've attached the code for the logical drive part.
strComputer = inputbox("computer?")

set objWMIService = getObject("winmgmts:" _

   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


set colDisks = objWMIService.ExecQuery _

    ("SELECT DeviceID, Description, Size, FreeSpace, FileSystem FROM Win32_LogicalDisk")

for each LogicalDisk in colDisks

'    for each strDisk in LogicalDisk

        If LogicalDisk.DeviceID <> "" Then 

            strDrive = strDrive & LogicalDisk.DeviceID & ", "

            strDrive = strDrive & LogicalDisk.Description & ", "

            strDrive = strDrive & "Total Space:" & DiskConv(LogicalDisk.Size) & ", "

            strDrive = strDrive & "Free Space:" & DiskConv(LogicalDisk.FreeSpace) & ", "

            strDrive = strDrive & "Filesystem:" & LogicalDisk.FileSystem & vbcrlf

        End If

'    Next


wscript.echo strDrive

Public Function DiskConv(size)

    If IsNull(size)  Then

        DiskConv = "Zero GB"

        Exit Function

    End If

    If size < 1000000000 Then 

        DiskConv = size / 1048576 

        DiskConv = round(DiskConv,1) & "MB"


        DiskConv = size / 1073741824

        DiskConv = round(DiskConv,1) & "GB"

    End If

End Function

Open in new window

Question by:mhsheldesk
    LVL 5

    Accepted Solution


    I am not sure if this is what you are looking for but check this out.

    Regards Tompa
    LVL 1

    Author Comment

    Tompa, the link you provided was not what I was looking for, but directly above it was just about exactly what I needed! Thanks, I'll deconstruct that code and get it working with mine.

    Expert Comment


    Can you post what you came up with?  I'm looking to do the same.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Run .exe file from network share 2 53
    vbscript, email results 2 22
    VBE and UNICO strings 2 20
    script 5 38
    Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now