Jump to content

Is there a way to get disk size if the drive is not formatted?


Recommended Posts

Is there a way to get disk size if the drive is not formatted? Only thing i know is the disk id number from the winodws disk management?

Thanks

you can use the wmi i guess

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive")
For $objItem In $colItems
    $size = $objItem.Size
Next

MsgBox(0, "DriveSize", $size)

[font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font]

Link to comment
Share on other sites

  • Moderators

Made the script a little more user friendly.

$strComputer = InputBox("Computer Name", "Please enter the computer name" & @Lf & "you wish to get drive size from.")
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive")
For $objItem In $colItems
    $size = $objItem.Size
Next
$size = $size / 1073741824
$capacity = StringFormat("%.2f", $size)
MsgBox(0, "DriveSize", $capacity & "GB")
Link to comment
Share on other sites

  • Moderators

Could someone help me turn $colDisks into an array?

$strComputer = InputBox("Computer Name", "Please enter the computer name" & @Lf & "you wish to get drive size from.")
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colDisks = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive")

For $objDisk In $colDisks
    $device = StringTrimLeft($objDisk.DeviceID, 4)  
    $size = $objDisk.Size / 1073741824
    $capacity = StringFormat("%.2f", $size) 
    MsgBox(0, "", "DeviceID: " & $device & @LF & "Disk Size: " & $capacity & "GB")
    If @error <> 0 Then ExitLoop
Next
Link to comment
Share on other sites

the only way is to create 2 or more arrays like this !?! Maybe there is another trick :">

#include <Array.au3>

$strComputer = InputBox("Computer Name", "Please enter the computer name" & @Lf & "you wish to get drive size from.")

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

$colDisks = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive")

$i=1

dim $Sizearray[1]

Dim $Disk[1]

For $objDisk In $colDisks

$device = StringTrimLeft($objDisk.DeviceID, 4)

$size = $objDisk.Size / 1073741824

$capacity = StringFormat("%.2f", $size)

_ArrayAdd($Disk,$device)

_ArrayAdd($Sizearray,$size)

MsgBox(0, "", "DeviceID: " & $device & @LF & "Disk Size: " & $capacity & "GB")

$i=$i+1

ReDim $Disk[uBound($Disk+$i)]

Redim $Sizearray[uBound($Sizearray+$i)]

If @error <> 0 Then ExitLoop

Next

_ArrayDisplay($Disk,"Device")

_ArrayDisplay($Sizearray,"Size")

Link to comment
Share on other sites

you can use the wmi i guess

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive")
For $objItem In $colItems
    $size = $objItem.Size
Next

MsgBox(0, "DriveSize", $size)

Thanks rudika..i get the following error. please see the attached screenshot

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...