PowerShell

Rediscovering My Software Developer Roots – First up PowerShell Photo Collector

Posted on September 19, 2010. Filed under: PowerShell | Tags: , |

I have recently decided to brush up my technical chops by taking on a development project.  I have had great fun staying current on all things Media Center related after completing my first Home Theater PC (HTPC) & XBox Elite integration into the home media ecosystem.  More on that subject in another post. Now that the system is complete for phase I and the HDHomeRun Prime is months away, it is time to develop some custom enhancements.

The spark to action was an upgrade to Version 3 of the HP MediaSmart Software for the Windows Home Server. The new version has a much improved Media Collector. However, I found it did not quite meet my needs. We often load photos from our digital cameras on various PCs around the house. I move these to the WHS Photos share.  The MediaSmart Collector just picks up the various images and places them under the Photos share including the user portion of the path. This means that the France Vacation pictures might be under “Photos/Dave/Photos/2010-July-France” while  Yakima Wine Weekend photos are under “Photos/Carolyn/Photos/YakimaWineWeekend”. Who has which photos can be a bit tedious to keep track of. This may work great for families were everyone imports pictures.  However, I’m the photographer and picture librarian in the household. I wanted my photos collected directly under the Photos share.

PowerShell seemed like it could easily solve my problem without too much overhead.

I needed to move the photos on various PCs to the WHS in a folder named for the event.  I had replicated some of these photos across PCs as a way to backup. Now seemed like a good time to free up some disk space since my music and photos are backed up to the cloud nowadays. There was a catch however. Some versions had been edited while the replica may not have been edited. I needed to preserve the edits and not assume that the WHS version was the correct version. I also wanted the collector to run as a scheduled job so all future camera uploads would automatically find their way to the WHS.

I had great fun discovering PowerShell and applying that knowledge to this problem. It took a bit of getting used to the Object pipeline, having moved from Perl. I found it great to work with. Along the way I discovered the key features of PowerShell and explored some dark corners, at least in terms of documentation.  The good news is that there is a vibrant community on the web to provide a rich set of examples.

In the end I got just what I needed. In Move Mode, replicated files are deleted from client PCs if they share the same pathname & hash as the image on the WHS. If files are not present on the WHS, they are collected to the WHS. Both files are preserved if they differ by hash code. All operations are logged so that files can then be manually reconciled.  After initial removal of replicas, reconciling the differing images, most follow-up runs will simply collect images.  This means I can schedule this as a daily task and bypass the otherwise nice implementation by HP. The script also has a Copy Mode if you do not want to remove files from the client PCs but still sweep to the WHS.

Code is very much alpha with some To-dos like making it work with an exclude list.  It should also be easy enough to extend this to Music files but that is not really a problem for me as the Zune software knows to download to the WHS.

Dave

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...