Reputation: 1345
I'm trying to create a script that will back up my phones files to my pc. Thus far I have :
$phone = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | Sort Manufacturer,Description,DeviceID | Where-Object {$_.Manufacturer -eq "motorola"}
Which shows:
__GENUS : 2
__CLASS : Win32_PnPEntity
__SUPERCLASS : CIM_LogicalDevice
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_PnPEntity.DeviceID="USB\\VID_22B8&PID_2E76&MI_00\\7&287261EF&0&000
0"
__PROPERTY_COUNT : 24
__DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : MpComp
__NAMESPACE : root\cimv2
__PATH : \\MyComproot\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_22B8&PID_2E76&MI_0
0\\7&287261EF&0&0000"
Availability :
Caption : XT1039
ClassGuid : {eec5ad98-8080-425f-922a-dabf3de3f69a}
CompatibleID : {USB\MS_COMP_MTP, USB\Class_ff&SubClass_ff&Prot_00, USB\Class_ff&SubClas
s_ff, USB\Class_ff}
ConfigManagerErrorCode : 0
ConfigManagerUserConfig : False
CreationClassName : Win32_PnPEntity
Description : XT1039
DeviceID : USB\VID_22B8&PID_2E76&MI_00\7&287261EF&0&0000
ErrorCleared :
ErrorDescription :
HardwareID : {USB\VID_22B8&PID_2E76&REV_0228&MI_00, USB\VID_22B8&PID_2E76&MI_00}
InstallDate :
LastErrorCode :
Manufacturer : motorola
Name : XT1039
PNPDeviceID : USB\VID_22B8&PID_2E76&MI_00\7&287261EF&0&0000
PowerManagementCapabilities :
PowerManagementSupported :
Service : WUDFRd
Status : OK
StatusInfo :
SystemCreationClassName : Win32_ComputerSystem
SystemName : MyComp
Now I'm trying to find the path to the phone to use in my powershell script, which will essentially copy all items it finds to another directory. How do I get a path to the phone, or how to I copy the files without having a path? I've tried using:
Get-ChildItem -Path "Computer\XT1039"
Which is the path that is present in the Windows File explorer, but this resolves the path to :
'C:\Users\Me\USB\VID_22B8&PID_2E76&MI_00\7&287261EF&0&0000
And an ItemNotFoundException is thrown, stating the location does not exit(which it doesn't). Also, My phone is not rooted, in case that is a part of potential solutions
Upvotes: 2
Views: 10247
Reputation: 209
Use this app: https://www.mtpdrive.com/download.html. It maps the phone to an actual drive that can be accessed by the Windows Command Line. The trial version allows the transfer of 30 files. I've tried the trial version on Windows 11 and it works for me.
Upvotes: -1
Reputation: 2448
Instead of PowerShell, you might try scripting ADB
commands to perform the backup. See here for more information.
ADB is part of the Android SDK.
-Edit in response to downvote. Please review this page for more detailed information as to why I answered with scripting ADB
instead of accessing the MTP device using PowerShell.
Upvotes: 3