Jump to content

Disk detection


sgufa
 Share

Recommended Posts

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
Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...