Sign in to follow this  
Followers 0
rlemoine002

Multiple USB Flashdrive Cleanup

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Hi JLogan.

Yes the flash drives are shown as mass storage device, but everything usb in the PC shows up also such as hubs, printing support (usb printer).

Share this post


Link to post
Share on other sites

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

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


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

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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