1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| $destination = "C:\FLS2"
$folder = "Desktop",
"Downloads",
"Favorites",
"Documents",
"Music",
"Pictures",
"Videos",
"AppData\Local\Mozilla",
"AppData\Local\Google",
"AppData\Roaming\Mozilla"
#####################################################################################
$username = gc env:username
$userprofile = gc env:userprofile
$appData = gc env:localAPPDATA
Add-Type -AssemblyName System.Windows.Forms
#nombre de fichiers à traiter, contient aussi les répertoires
$Files= Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force
$Files.Count
#taille totale des fichiers à traiter
$currentFolderSize = ($Files| Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
for ($i = 1; $i -lt 101; $i++ ){for ($j=0;$j -lt 10000;$j++) {} write-progress -activity "Copie en Cours..." -status "% Complete:" -percentcomplete $i;}
###### Restore data section ######
if ([IO.Directory]::Exists($destination + "\" + $username + "\"))
{
$OUTPUT= [System.Windows.Forms.MessageBox]::Show("Le dossier backup pour $username existe, on Restaure ?" , "Restauration" , 4)
if ($OUTPUT -eq "YES")
{
write-host -ForegroundColor green "Restauration des donnees de $username"
foreach ($f in $folder)
{
$currentLocalFolder = $userprofile + "\" + $f
$currentRemoteFolder = $destination + "\" + $username + "\" + $f
$currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
$currentFolderSizeRounded = [System.Math]::Round($currentFolderSize)
write-host -ForegroundColor cyan " $f... ($currentFolderSizeRounded MB)"
Copy-Item -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder
if ($f -eq "AppData\Local\Mozilla") { rename-item $currentLocalFolder "$currentLocalFolder.old" }
if ($f -eq "AppData\Roaming\Mozilla") { rename-item $currentLocalFolder "$currentLocalFolder.old" }
if ($f -eq "AppData\Local\Google") { rename-item $currentLocalFolder "$currentLocalFolder.old" }
}
rename-item "$destination\$username" "$destination\$username.restore"
[System.Windows.Forms.MessageBox]::Show("Restauration complete!" , "Restauration")
}
else
{
write-host -ForegroundColor yellow "Annulation"
exit
}
}
###### Backup Data section ########
else
{
$OUTPUT= [System.Windows.Forms.MessageBox]::Show("Pret pour le backup de $username ?" , "Backup" , 4)
if ($OUTPUT -eq "YES")
{
Get-Process | Where { $_.Name -Eq "OUTLOOK" } | Kill
write-host -ForegroundColor green "Backup des donnees de $username"
foreach ($f in $folder)
{
$currentLocalFolder = $userprofile + "\" + $f
$currentRemoteFolder = $destination + "\" + $username + "\" + $f
$currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB
$currentFolderSizeRounded = [System.Math]::Round($currentFolderSize)
write-host -ForegroundColor cyan " $f... ($currentFolderSizeRounded MB)"
Copy-Item -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder
}
$oldStylePST = [IO.Directory]::GetFiles($appData + "\Microsoft\Outlook", "*.pst")
foreach($pst in $oldStylePST)
{
if ((test-path -path ($destination + "\" + $username + "\Documents\Outlook Files\oldstyle")) -eq 0){new-item -type directory -path ($destination + "\" + $username + "\Documents\Outlook Files\oldstyle") | out-null}
write-host -ForegroundColor yellow " $pst..."
Copy-Item $pst ($destination + "\" + $username + "\Documents\Outlook Files\oldstyle")
}
[System.Windows.Forms.MessageBox]::Show("Backup complet!" , "Sauvegarde")
}
else
{
write-host -ForegroundColor yellow "Annulation"
exit
}
} |