Sign in to follow this  
Followers 0
sgufa

Disk detection

4 posts in this topic

Hi there.

Is there a way to detect how many DISKS(not volumes) are installed in a machine, including disk name(like in device manager) and then detect partitions and their name?

Please help me...

Share this post


Link to post
Share on other sites



Hi there.

Is there a way to detect how many DISKS(not volumes) are installed in a machine, including disk name(like in device manager) and then detect partitions and their name?

Please help me...

search the help file next time...

$var = DriveGetDrive( "all" )
If NOT @error Then
    MsgBox(4096,"", "Found " & $var[0] & " drives")
    For $i = 1 to $var[0]
        MsgBox(4096,"Drive " & $i, $var[$i])
    Next
EndIf

Share this post


Link to post
Share on other sites

search the help file next time...

And you read better the questions...! I specified "NOT VOLUMES..."

Share this post


Link to post
Share on other sites

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colDiskDrives = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
 
For $objDrive In $colDiskDrives
    ConsoleWrite( "Physical Disk: " & $objDrive.Caption & " -- " & $objDrive.DeviceID & @CRLF)
    $strDeviceID = StringReplace($objDrive.DeviceID, "\", "\\")
    $colPartitions = $objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
            $strDeviceID & """} WHERE AssocClass = " & _
                "Win32_DiskDriveToDiskPartition")
 
    For $objPartition In $colPartitions
        ConsoleWrite( "Disk Partition: " & $objPartition.DeviceID & @CRLF)
        $colLogicalDisks = $objWMIService.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                $objPartition.DeviceID & """} WHERE AssocClass = " & _
                    "Win32_LogicalDiskToPartition")
 
        For $objLogicalDisk In $colLogicalDisks
            ConsoleWrite( "Logical Disk: " & $objLogicalDisk.DeviceID & @CRLF)
        Next
        ConsoleWrite(@CRLF)
    Next
    ConsoleWrite(@CRLF)
Next

http://www.microsoft.com/technet/scriptcen...05/hey0523.mspx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0