Powershell – Compressing folders with long paths

powershell

I am now the proud owner of my company's off-boarding script (Yay!). I have been going through the code and testing, and I noticed that on some users' homefolders I am hitting PowerShell's 260 character limit. This is a problem because our policy states that anyone on "litigation hold" that leaves the company needs to have their entire homefolder compressed and stored until legal releases it (so forever in other words). The rest of the script runs great and takes care of EVERYTHING else so I would like this process to stay in PowerShell.

I have tried numerous ways/methods/workarounds and I havent found one that works yet. Here is what I have tried:

AlphaFS : Can get all of the file names, but chokes when I send the output to a native cmdlet (Not surprising)
AlphaFS Compress : Not recursive
7-Zip : Doesn't retain timestamps properly
ICSharpCode.SharpZipLib : Hits PS character limit

*Edit : I also tried QuickIO.NET but didn't get passed the PS limit with the compress method.
*Edit2 : Tried System.IO.Compression.FileSystem – Hits PS character limit

I unfortunately can't post the code, but the idea is pretty simple.

HomeFolder –> PowerShell –> CompressedFile

I can load whatever modules I might need to in the script but its got to stay PowerShell and the folder contents need to be compressed into one file. I am hoping this is even possible.

Any help would be appreciated.

Thank you

Best Answer

I would recommend using emcopy / robocopy to move the directory to a shorter path length.

Then you would easily be able to manipulate it how you want in powershell.

Even if that is zipping it and then moving it back with emcopy

Related Topic