Copying files between path providers with PowerShell in EPiServer
August 18th, 2011 by Adam Najmanowicz | 63 CommentsWe had a situation in the company this week which required us to deliver the whole EPiServer virtual path provider file structure to the client ? zipped. Easy enough? go to the EpiServer VPP directory and? well? ok? hmm? so the path provider is versioning and as a consequence the physical organization of files on the disk does not make any sense for a human trying to browse it.
Fine! So let?s create a native provider and do a copy and paste within the file manager?. hmm an exception complaining about the provider incompatibility?
Naturally, my knee-jerk reaction is ? let?s do it with the PowerShell? which I recall was doing something like this in it?s previous version? The example I?ve tested and placed in the ?Samples? tab was:
cd VPP:\ cd \Documents\ get-childitem -recurse | copy-item -destination \DocumentsNonVersioningVPP\
This worked well but flattened the directory structure ? in other words useless for our client.
I?ve tried what should work in a plain PowerShell:
cd VPP:\ copy-item -path vpp:\Documents\* -destination vpp:\DocumentsNonVersioningVPP\ -recurse -force
Now that didn?t work at all, and turned out to be a bug in my PowerShell plugin?s PSDrive provider. Unfortunately when I attempted to fix it by implementing the copy in the naive way ? using UnifiedDirectory?s Copy method I?ve run into the same exception about incompatibility between the classes that I?ve seen when trying to copy the files form the file manager.
Mmmkay? I?ll just implement the recursion myself? Read the rest of this article »