Bonjour,

J'ai adapté à mon utilisation un script trouvé sur le net

Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
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
$destination = "C:\Backup"
 
$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
 
 
###### 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!" , "KABA") 
	}
 
	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!" , "KABA") 
 
    else
	{
		write-host -ForegroundColor yellow "Annulation"
		exit
	}
	}
 }

J'aimerais pouvoir afficher lors de son exécution une barre de progression, mais je n'arrive pas à trouver sur le net ou exactement placer la ligne de code de la barre dans mon script et si la syntaxe est à conserver dans l'état

Voici la ligne :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
for ($i = 1; $i -lt 101; $i++ ){for ($j=0;$j -lt 10000;$j++) {} write-progress -activity "Search in Progress" -status "% Complete:" -percentcomplete $i;}
Pourriez vous me renseigner ? Sachant que je découvre PS

Merci d'avance, à demain