Jump to content

Multiple USB Flashdrive Cleanup


Recommended Posts

I am looking for a way to use Autoit to do the clean,create primary partition, format, etc that is normally done in Diskpart.  The trick is that I am using a hub that holds 20 USB flashdrives, AND when the selection to pick the disk is done, to disregard the 2 local hard drives in the PC so they don't get wiped out.

I have searched and tried various things without success.

does anybody have any ideas?

Thank you.

Link to comment
Share on other sites

  • Moderators

So, let's start with identifying the drives by type. Does this return all 20 drives as you would expect? And if so, what do they show up as (mass storage device, composite device, etc)?

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$aOS = $oWMI.ExecQuery("Select * from Win32_USBHub")

    For $sItem In $aOS
        $sDevID = $sItem.DeviceID & ":" & @CRLF
        $sPNPID = "     " & $sItem.PNPDeviceID & @CRLF
        $sDesc = "     " & $sItem.Description & @CRLF
        $sName = "     " & $sItem.Name & @CRLF
        ConsoleWrite($sDevID & $sDesc & $sPNPID & $sName & @CRLF)
    Next

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Right, which means you will need to narrow your search, something like this:

Local $oWMI, $oUSB, $sDevID, $sPNPID, $sDesc, $sName

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$oUSB = $oWMI.ExecQuery("Select * from Win32_USBHub")

    For $sItem In $oUSB
        If StringInStr($sItem.Name, "Mass Storage") Then
            $sDevID = $sItem.DeviceID & ":" & @CRLF
            $sPNPID = "     " & $sItem.PNPDeviceID & @CRLF
            $sDesc = "     " & $sItem.Description & @CRLF
            $sName = "     " & $sItem.Name & @CRLF
            ConsoleWrite($sDevID & $sDesc & $sPNPID & $sName & @CRLF)
        EndIf
    Next

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I believe the Win32_DiskDrive is also an appropriate class to query...(filter by InterfaceType=USB)

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$oWMICol = $oWMI.ExecQuery("Select * from Win32_DiskDrive Where InterfaceType = 'USB'")

For $oInstance In $oWMICol
    $sCaption = $oInstance.Caption & ":" & @CRLF
    $sPNPID = "     " & $oInstance.PNPDeviceID & @CRLF
    $sDesc = "     " & $oInstance.Description & @CRLF
    $sDevID = "     " & $oInstance.DeviceID & @CRLF
    ConsoleWrite($sCaption & $sDesc & $sPNPID & $sDevID & @CRLF)
Next

 

Link to comment
Share on other sites

Actually, the results I get from spudw2k are more in line with what I'm looking for.

At the end of each flase drive "info" section, the line shows:  \\.\PHYSICALDRIVEnumber.

This number seems to correspond to the List Disk command from Diskpart.  Is this correct?

 

Thanks to both of you for helping.

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