4

I am trying to open a command prompt to access folders of a USB connected windows phone. I have tried several commands like the following but to no avail.

wmic logicaldisk get name

GET-WMIOBJECT win32_diskdrive | Where { $_.InterfaceType -eq 'USB' }

Could someone suggest me the best way to accomplish this without using any tool? My task is to access the mobile device to adjust language settings using PowerShell commands.

Phone : Lumia 1020 running Windows Phone 8.

2 Answers 2

0

To get a list of USB drives attached to the PC, execute this command.

Get-WmiObject Win32_Volume -Filter "DriveType='2'"

If your mobile is attached as a USB disk, it should show up. From the data you get back, you should be able to extract things like Caption, Label, Name and DriveLetter. Then you can automate things a little bit further:

cd (Get-WmiObject Win32_Volume -Filter "DriveType='2'" | Where-Object label -eq "YourDiskName").DriveLetter

EDIT: Since Get-WmiObject command is now depreciated, the preferred way is now to use Get-CimInstance.

 Get-CimInstance -Query "SELECT * FROM Win32_LogicalDisk WHERE DriveType=2"
5
  • Hi Jan, Get-WmiObject Win32_Volume -Filter "DriveType='2'" is not tracing usb connected windows phone in powershell.
    – vudesw
    May 15, 2015 at 17:14
  • Hi Jan, able to connect with USB devices for the above mentioned command but not able to with Phone devices connected via USB cable.
    – vudesw
    May 18, 2015 at 23:23
  • Perhaps a different DriveType? I don't have a Windows phone, but my Android appears to mount as a DriveType = 3 Feb 3, 2016 at 14:16
  • ....or perhaps it is showing something else (the only 3 drives displayed in the UI are C: D:, and my phone, but the 3rd drive remains in my Get-WmiObject list even when I unplug my phone, and the Caption is unclear: \\?\Volume{0b454197-46b5-40c4-8683-c9e1265afa55}) Feb 3, 2016 at 14:30
  • the command Get-WmiObject is deprecated, unfortunately the solution is not valid anymore :( Jan 8, 2022 at 10:16
0

You can get the phone's top-level directory using this function, then add the root folder name from explorer e.g. 'Internal Shared Storage', 'Card', etc.

function Get-PhoneMainDir($phoneName) {
  $o = New-Object -com Shell.Application
  $rootComputerDirectory = $o.NameSpace(0x11)
  $phoneDirectory = $rootComputerDirectory.Items() | Where-Object {
    $_.Name -eq $phoneName } | select -First 1

  if ($phoneDirectory -eq $null) {
    throw "Not found '$phoneName' folder in This computer. Connect your phone."
  }

  return $phoneDirectory;
 }

$phoneName is the name of the phone in Explorer, e.g. 'Pixel 5a'

A full example is available here:

https://github.com/nosalan/powershell-mtp-file-transfer/blob/master/phone_backup_recursive.ps1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.