14

If I connect my digital camera via USB, Windows Explorer lists it under Computer as a device. I can browse it using Explorer, see folders, file properties etc, and copy/delete files.

This is all without setting the camera to be a storage device (in which case I believe the camera will show up as a flash drive, with an assigned drive letter, making this easy).

Is there a way for me to access and browse the files and folders on the camera using Windows PowerShell? As far as I can tell, no drive letter is (automatically) assigned to the device.

I'm not looking for workarounds - I can copy the files with explorer, not problem. I'm asking because I want to play around with PowerShell :-)

Thanks

UPDATE:

I've managed to get a Win32PnPEntity object of the camera using the following:

Get-WmiObject Win32_USBControllerDevice | ForEach-Object { $_; [Wmi]$_.Dependent }

Followed by Get-WmiObject win32_pnpentity -filter "name='Canon PowerShot A480'" using the name I got from the previous command (PNPDeviceID would probably be a better choice but the name was easier to type :P )

However, I don't know if I can do anything useful with that Win32PnPEntity object.

Pieter Müller
  • 4,573
  • 6
  • 38
  • 54
  • 1
    FYI: Windows 10 includes a `Get-PnpDevice` function: https://technet.microsoft.com/en-us/itpro/powershell/windows/pnpdevice/get-pnpdevice. That's just helpful wrapper for `Get-WmiObject win32_pnpentity` though – JohnLBevan Apr 10 '17 at 15:45
  • github.com/nosalan/powershell-mtp-file-transfer on this repo there is a script to copy via MTP from android storage using Powershell – nan May 22 '19 at 19:19

3 Answers3

5

I have just created a PowerShell script that is able to crawl my usb attached Android device, derived from the following website:

http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/26/use-powershell-to-work-with-windows-explorer.aspx

I am using the following APIs:

  1. Instantiation of a Shell.Application COM object:

$o = New-Object -com Shell.Application

  1. Get a specific Namespace, i.e. the list of root folders:

$folder = $o.NameSpace(0x11)

0x11 refers to the enum constant ShellSpecialFolderConstants.ssfDRIVES; see https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx

  1. Recursively traverse this $folder:

$folder.GetFolder() and $folder.Items

See my complete working gist: https://gist.github.com/cveld/8fa339306f8504095815

Carl in 't Veld
  • 1,363
  • 2
  • 14
  • 29
5

You can combine information from the two following articles: https://devblogs.microsoft.com/powershell/get-usb-using-wmi-association-classes-in-powershell/

This will allow you to retrieve the device ID associated with your specific USB device (from the Name property, for example).

Then use WMI for accessing the files: How can I create a PowerShell script to copy a file to a USB flash drive?

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
David Brabant
  • 41,623
  • 16
  • 83
  • 111
  • +1 Thanks David, as noted in my update, this has helped me get a `Win32_PnPEntity` object of the camera, which feels closer to a solution, I just don't know quite what to do with it yet. – Pieter Müller Mar 05 '12 at 15:09
  • 1
    This is not a working solution for PNP portable devices which is what the OP is looking for. The second link uses `get-wmiobject win32_logicaldisk` which usb camera will not show up under. – Despertar Oct 18 '14 at 21:14
-1

I'd start by running get-PSDrive and see if the camera shows up.

If it does, you should be able to treat it as a normal drive and use the copy-item cmdlet to move the items:

Reference: http://technet.microsoft.com/en-us/library/dd347638.aspx

regards Arcass

Arcass
  • 932
  • 10
  • 19
  • 2
    imo it is not that easy.. :) I tried to download pics from Canon attached via USB some time ago, but still don't have working solution.. :| – stej Mar 02 '12 at 11:09
  • @Arcass I did run get-psdrive before posting, and the device does not show up as a drive. I don't know if there is perhaps a linux-esque way of mounting it, though. – Pieter Müller Mar 02 '12 at 15:05
  • I think the camera shows up in explorer using shell extentions that use com objects through its driver. You could try to figure out how to use those com objects, but the easiest approach is probably switching the camera to be a storage device. – Winfred Mar 02 '12 at 20:35