Dropbox PowerShell Provider

§ July 16, 2016 00:47 by beefarino |

Life’s nuts, but I managed to create another PowerShell Provider I desperately need.  This one mounts your Dropbox account as a PowerShell drive.  Its functionality is limited, but it’s still wicked awesome.

The module is available in the gallery, and the source code is available on github.  The provider is built on top of P2F so the code is minimal.

The available feature set is really driven by my immediate needs.  In short, I found myself needing to filter large collections of files from across the corporate Dropbox hive and push their contents to Azure blob storage.  So at present, this first release supports basic navigation, as well as the get/set-content cmdlets.

Usage is pretty straightforward if you’ve used PowerShell modules and providers.  This example below mounts a Dropbox account and lists the contents in the root path:

import-module dropbox;
new-psdrive -name dp -psprovider dropbox -root '';
# powershell will open a window here to allow you 
# to authenticate with dropbox
cd dp:

Getting the content of files from Dropbox is a simple matter of using the get-content cmdlet.  The provider transfers all files as raw byte arrays, so you need to take special care when saving the files locally:

$bytes = get-content dp:/data/file.txt;
[io.file]::writeAllBytes( "c:\data\file.txt", $bytes);
get-item c:\data\file.txt;

Eventually I’d like this module to support full item operations on the Dropbox hive.  But, you know me, I’ll get to it when I actually need it.


Disappearing Drives in WMF 5.0 Preview

§ April 21, 2015 17:04 by beefarino |

Just a quick note about something I uncovered in the WMF 5.0 preview.  This one’s been frustrating me for a few weeks as I’ve prepped demos for the PowerShell Summit.

If you create a new PowerShell drive in your session that has a single-letter name, the drive will be forcibly removed  unless it’s backed by the FileSystemProvider.

To see this in action, run the following script in PowerShell 5 preview:

new-psdrive z -psp filesystem -root 'c:\'
new-psdrive y -psp registry -root 'hkcu:\'
sleep -second 5


You’ll notice that the FileSystemProvider z: drive sticks around, where the RegistryProvider y: drive disappears.

Now that I’ve figured out what’s happening, I feel better about pushing the new version of Simplex to the gallery!

A Dirt Simple PowerShell Hosting Example

§ October 15, 2014 13:40 by beefarino |

Earlier today I responded to a shout for help from twitter friend and fellow PowerShell hacker Tim Meers:


After sending Tim some code showing how to host simple PowerShell scripts in your application, I’ve received several requests from others for the same.  I figured it was worth a quick blog post.

The annotated code is below.  This host accepts an item path as input, and uses PowerShell to fetch and format the item as text.

using System;
using System.Linq;

// you'll need to add a reference to System.Management.Automation
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace HostSample
    class Program
        // to run this application, specify a path to an item
        //  e.g.:
        //      c:\
        //      env:/computername
        //      hkcu:/software
        static void Main(string[] args)
            // create a RUNSPACE - this is used to maintain state between pipelines.
            //  e.g., variables, function definitions, etc
            using (var runspace = RunspaceFactory.CreateRunspace())
                // open the runspace before you use it

                // set the default runspace for the process;
                //  this is necessary for some features and cmdlets to work properly
                Runspace.DefaultRunspace = runspace;
                // create a POWERSHELL pipeline
                using (var powershell = PowerShell.Create())
                    // assign the runspace to the pipeline
                    powershell.Runspace = runspace;

                    // build up the pipeline
                        .AddParameter("path", args[0])
                        .AddCommand( "out-string");

                    // execute the pipeline
                    var results = powershell.Invoke();

                    // output the results
                    Console.WriteLine( results.FirstOrDefault() );

If you have any questions, please ask them in the comments.


Rocket Science

§ October 14, 2014 15:01 by beefarino |

So, funny story in honor of Ada Lovelace day.

My first job was pretty amazing.  I worked with a bunch of really smart people doing really smart things.  Space things.  And optics things.  Now my role on this team was fairly meager – I basically helped the documentation team try and capture all of the smart things the other smarter people were doing – but it was still amazing to be around that stuff.  Space telescopes, satellites, cell phones, automotive components, this team helped design all sorts of useful and interesting crap.

Anyway, one woman on the engineering team – we shall call her Mary although that’s not her name – had a very sharp sense of humor and keen hearing, both of which come into play in this tale.  One evening we were out celebrating …. something – a release perhaps?  maybe a project wrap-up?  There was drinking and nogoodnicking.  One of my outside-of-work friends from my previous stint in grad school was there – let’s call him Joe.  This evening Joe happened to be hitting on Mary.  Hard.  I watched from my bar stool several meters away while he strutted about her like a peacock with a spare ego.  Mary was unimpressed and Joe eventually took the hint.

So Joe politely adjourns from Mary and joins me at the bar.  I asked him, “So, what do you think of Mary?  She’s kind of awesome, right?”

Joe sighed and said, “Yeah, she’s cute.  But she’s no rocket scientist.”

I started laughing.  That loud obnoxious laugh you may know.  Joe wanted to know why.  So I turned around and shouted, “Hey Mary, what is it you do for a living?”

She finished her beer, slammed the stein on the table, stood up to look Joe square in the eye and as she was leaving, she said:

I’m a fucking rocket scientist.

And the best part?  It was true.  100% honest.  She did rockets for a living.  A literal rocket scientist that sends things into space.  Ego Joe never stood a chance.


So originally this post was a bit different.  It wasn’t a story, it was a rant.  I didn’t like the rant so I wanted to turn it into something positive. 

Here’s the thing – Ada Lovelace is important, and I’ve told my girls about her because I want them to know that women have had a profound impact on society.  Having that history is vital for them I think – I do believe the technical contributions from women are under-celebrated and often deliberately downplayed.  So I want them to know about Ada and what she contributed, and that we can literally thank her for my career and our family’s happiness.

But I know that won’t do anything real for them.  I mean, why should I expect stories of Ada to have a significant impact on my girls, when similar stories about C.S. Babbage had fairly milquetoast effects on me when I was their age.  Interesting, perhaps necessary, but it won’t light their fuse.

Which is why I spend so much time finding Marys.  Living people my girls can see doing real and amazing things, people they can talk to about wonders and interests.  Sure I want them to know that “once upon a time there was Ada,” but I think knowing that there is Mary right here, right now, doing really amazing stuff, is far more important to their mindset.

My biggest fear for my daughters is that they will come to believe that they can’t do something because of their gender or sex.  My biggest tool to counteract that fear, is to show them someone who can – someone like Mary.