• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1382
  • Last Modified:

Get Physical Drive from Logical Drive

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

1 Solution

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


Regards Tompa
mhsheldeskAuthor Commented:
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.

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now