So, to make it simple, i'm trying to copy user profiles through a shared folder on multiple clients, it works fine, but i can't seem to make a log file that works with it
As it is, i expected that $? would always end up giving me True for each command (Unless it kinda crashes in the middle of copying), since it's properly copying every folder i want, but it's not... It gives me a True once, then it's all false, even though it did everything correctly
Foreach ($User in $Users){
Foreach ($TargetDirectory in $Directories){
$TestPath = Test-Path -Path "\\$Client\Users\$User"
If ($TestPath -eq $True) {
Robocopy "\\$Client\Users\$User\$TargetDirectory" "C:\SAV\$Client\$User\$TargetDirectory" /E /MIR
$Date = get-date -f yyyy-MM-dd
$Path = "C:\Logs\($Date)Sauvegarde_Profils_$Client.txt"
New-Item -Path $Path -Force
$Result = "Copie du dossier $TargetDirectory, appartenant à $User = $? dans $Client"
Add-Content -Path $Path $Result
}
}
}
}
Here's a sample of the logfile (in French, but it's just to show that it's almost working as intended) :
Copie du dossier Documents, appartenant à firmerie.alain = True pour CLIENT-1
Copie du dossier Desktop, appartenant à firmerie.alain = False pour CLIENT-1
...(Only False after that point)