Shooting tethered on my Nikon D700… using PowerShell

This content is 15 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

About this time last week, James O’Neill was explaining to me how Windows Image Acquisition (WIA) could be used to control my camera over a USB connection. I’m not sure if he told me, or if I suddenly realised, but somewhere along the way came the realisation that I could use this to take a picture – i.e. to drive the camera remotely – and James very kindly shared some Windows PowerShell commands with me.

Today, James published the results of his work, saving me a lot of research into WIA and a related subject – Picture Transfer Protocol (PTP) but, unlike James’ Pentax K7, it seems that my Nikon D700 will allow me to use this to actually take a picture (I haven’t tried on my Canon Ixus 70… with or without the CHDK).

James’ code showed me how to call WIA as a COM object:

$WIAdialog = New-Object -ComObject "WIA.CommonDialog"
$device = $WIAdialog.ShowSelectDevice()

Following this I had an object called $device that I could manipulate as I liked and $device | get-member returned the following methods and properties:

   TypeName: System.__ComObject#{3714eac4-f413-426b-b1e8-def2be99ea55}

Name           MemberType Definition
—-           ———- ———-
ExecuteCommand Method     IItem ExecuteCommand (string)
GetItem        Method     IItem GetItem (string)
Commands       Property   IDeviceCommands Commands () {get}
DeviceID       Property   string DeviceID () {get}
Events         Property   IDeviceEvents Events () {get}
Items          Property   IItems Items () {get}
Properties     Property   IProperties Properties () {get}
Type           Property   WiaDeviceType Type () {get}
WiaItem        Property   IUnknown WiaItem () {get}

$device.Properties was kind of interesting but with $device.Commands I was really getting somewhere:

CommandID                               Name          Description
———                               —-          ———–
{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}  Synchronize   Synchronize
{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}  Take Picture  Take Picture

Seeing that there was a command to take a picture got me thinking and looking back at the device methods I could see ExecuteCommand so I tried calling it:

$device.executecommand('{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}')

I was amazed to find that my camera did exactly what it was told and fired the shutter! I need to do some more testing, to see if I can control the focus, or return a live preview, etc. but controlling a remote device, over a USB connection, using nothing more than a few basic scripting commands made me feel like a real techie again (even if it was James’ code that got me started!). Who knows, I may even teach myself to code again (as I’ve threatened several times over the last few years) and write an application to remotely control my camera.

Ironically, at the start of last week I was trying to figure out how to take time-lapse photos of the extension that I’m having built on my house right now but it wasn’t software that held me back, it was practical issues like leaving a camera outside for days on end in all weathers and providing power to it. Now, if only I had a 25 metre USB cable (!), I could hook up a cheap webcam and set a script to take a picture every hour or so…

Further reading

WIA Camera Devices on MSDN.
WIA Camera support in Windows Vista (part 1 and part 2).
WIA 2.0 and digital camera interaction.

6 thoughts on “Shooting tethered on my Nikon D700… using PowerShell

  1. Autofocus should work but you can’t actually focus the camera using PowerShell. You could also just set a really narrow aperture in which case just about everything will be in focus!

  2. USB over 25 ft – no problem. I regularly use USB over 17 metres to control a Canon Powershot on a mast. I use USB 2 extenders – a couple of quid off Ebay – and run a cat5 cable between them. Works perfectly.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.