martes, 18 de marzo de 2008

WideOpen Web: When Things Go Wrong - A Restore Windows PowerShell Script for the December 2007 FolderShare Bug

Ok, so it's not that recently that FolderShare decided to delete all your files that had certain characters (accents, trademark signs, etc.). This happened at the beginning of December 2007. You can find a detailed description of the problem (and Microsoft's response) here: http://www.techcrunch.com/2007/12/11/foldershare-autodeletes-files-whoops/

I am a heavy user of FolderShare and have been mostly happy about it, using it to synchronize files between my Laptop and my two desktops. This bug really bit me, since I use those "special characters" a lot since I am Mexican and like to spell correctly in Spanish. Ever since the bug bit me I just copied all my deleted files from FolderShare's trash to a brand new folder under my documents that I creatively named "FolderShare Stupidity". Literally thousands of my files now lived there instead of in my carefully crafted personal structure. All that was left in the original folders was the FolderShare marker "*.p2p" files.

Today I had a little too much time on my hands so I decided to play a bit with Windows Powershell (I had never used it before). It sounded like the right tool for the job in trying to build a simple script to restore my files to their proper locations. I originally intended to write a quick C# program to fix this but after today I can tell you that PowerShell is definitely the right tool for the job.

This is the script that I wrote:

#* FileName: FixFolderShare.ps1

#*=============================================================================

#* Script Name: FixFolderShare.ps1

#* Created: 170308

#* Author: Hector Obregon

#* Company: emLink

#*=============================================================================

#* Purpose: Fix FolderShare incorrectly moved files

#*=============================================================================


$items = get-childitem -path "C:\Users\hobregon\Documents" -recurse -include *.p2p

foreach ($f in $items)

{

$origname = $f.name.Replace(".p2p", "")

Set-Location "C:\Users\hobregon\Documents\FolderShare Stupidity"

$origitem = get-childitem $origname

$origfile = $origitem.fullname

$destfile = $f.fullname.Replace(".p2p", "")

Write-Host $origfile

Write-Host $destfile

copy $origfile $destfile

del $f.fullname

}

Be very careful if you decide to use the script yourself. I don't make any guarantees and will not be held responsible for any loss of data you may experience. Caveat emptor.
Having gotten that out of the way, this is what you need to do:

1. Download and install Windows PowerShell 1.0 following instructions here: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx

2. Open notepad and copy the script above and save it somewhere on your disk. Do not execute it yet.

a. Replace "C:\Users\hobregon\Documents" in the first line of the script above with a root folder underwhich you have many "orphaned" p2p files.

b. Replace "C:\Users\hobregon\Documents\FolderShare Stupidity"
inside the foreach loop above with the folder path in which you restored all your FolderShare deleted files after the bug hit.

c. Save the modified script.

3. Launch PowerShell and execute this statement to allow it to execute local unsigned scripts: set-executionpolicy RemoteSigned

4. Execute the modified script by navigating to the directory where you saved it and typing .\ before the name of your modified script file.

5. If you are paranoid about script execution, restore PowerShell execution policy to deny scripts like this: set-executionpolicy Restricted

This script will try to find all of your orphaned P2P files and restore them to their proper locations. It will not delete any of your files except the orphaned P2P FolderShare marker files.

I just found out today that FolderShare has come out with a new "Windows Live" version. I will wait it out and make sure it is stable first.

No hay comentarios:

Publicar un comentario