3

I've gone through few posts and articles that discuss how to use powershell access usb drive like:

But none of them actually "answers" the question. The last post shared also says no one has ever created an MTP solution because of certain limitations that MTP (protocol) itself has.

One route I've taken kind of hit a wall; I don't know what to do next (with the wmi object). I've used the following vbscript program, and made note of the device id of the device I am interested in obtained from here:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery _
    ("Select * From Win32_USBControllerDevice")

For Each objDevice in colDevices
    strDeviceName = objDevice.Dependent
    strQuotes = Chr(34)
    strDeviceName = Replace(strDeviceName, strQuotes, "")
    arrDeviceNames = Split(strDeviceName, "=")
    strDeviceName = arrDeviceNames(1)
    Set colUSBDevices = objWMIService.ExecQuery _
        ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
    For Each objUSBDevice in colUSBDevices
        Wscript.Echo objUSBDevice.Description
    Next    
Next

I've kind of plugged that in the below powershell command to get the wmi object:

Get-WmiObject win32_pnpentity -filter "DeviceID='<the_device_id>'" 

Now I think I have the WMI object. But what can I do with it.

Coming from the last post I've linked to I have a hunch there is a COM way to deal with this. How do we have to do that?

Community
  • 1
  • 1
deostroll
  • 11,661
  • 21
  • 90
  • 161

1 Answers1

0

To find MTP devices in Power Shell use this command:

Get-WmiObject -class win32_pnpentity -computername localhost | where-object {$_.HardwareID -like "*MTP*"} | format-list

Example output for a Samsung Galaxy S5

__GENUS : 2 __CLASS : Win32_PnPEntity __SUPERCLASS : CIM_LogicalDevice __DYNASTY : CIM_ManagedSystemElement __RELPATH : Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\\6&8F62A49&0&0000" __PROPERTY_COUNT : 24 __DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement} __SERVER : -*- Computer Name -*- __NAMESPACE : root\cimv2 __PATH : \\-*- Computer Name -*-\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\\6&8F62A49&0&0000" Availability : Caption : -*- device display name in explorer -*- ClassGuid : {eec5ad98-8080-425f-922a-dabf3de3f69a} CompatibleID : {USB\MS_COMP_MTP, USB\Class_06&SubClass_01&Prot_01, USB\Class_06&SubClass_01, USB\Class_06...} ConfigManagerErrorCode : 0 ConfigManagerUserConfig : False CreationClassName : Win32_PnPEntity Description : SM-G900P DeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&8F62A49&0&0000 ErrorCleared : ErrorDescription : HardwareID : {USB\VID_04E8&PID_6860&REV_0400&MS_COMP_MTP&SAMSUNG_Android, USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_Android, USB\SAMSUNG_MOBILE&MS_COMP_MTP&SAMSUNG_Android, USB\SAMSUNG_MOBILE&MI_00...} InstallDate : LastErrorCode : Manufacturer : Samsung Electronics Co., Ltd. Name : -*- device display name in explorer -*- PNPDeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&8F62A49&0&0000 PowerManagementCapabilities : PowerManagementSupported : Service : WUDFRd Status : OK StatusInfo : SystemCreationClassName : Win32_ComputerSystem SystemName : -*- Computer Name -*-

Audreth
  • 67
  • 5
  • 3
    okay how does this actually help me browse the mobile phone's file system (shared via mtp)? – deostroll Jun 02 '15 at 11:30
  • check here: https://github.com/nosalan/powershell-mtp-file-transfer/blob/master/phone_backup.ps1 – nan May 22 '19 at 19:20