# ------------------------------------------------------------ # Restore Leica LAS X settings to new Windows profiles # ------------------------------------------------------------ # This script uses /COPY:DAT and not /COPYALL so that rights on the files are not copied. $CsvFile = "C:\Temp\Users.csv" $SourceRoot = "E:\OldUsers" $DestinationRoot = "C:\Users" $LogFile = "C:\Temp\RestoreLeicaSettings.log" Start-Transcript -Path $LogFile if (-not (Test-Path $CsvFile)) { Write-Host "ERROR: CSV file not found: $CsvFile" Stop-Transcript exit } $Copied = 0 $MissingSource = 0 $MissingUser = 0 $Errors = 0 foreach ($Entry in Import-Csv $CsvFile) { $UserName = $Entry.Name $Source = Join-Path $SourceRoot "$UserName\AppData\Roaming\Leica Microsystems\LAS X" $Destination = Join-Path $DestinationRoot "$UserName\AppData\Roaming\Leica Microsystems\LAS X" Write-Host "" Write-Host "----------------------------------------" Write-Host "Processing user: $UserName" # Check if Windows user exists if (-not (Get-LocalUser -Name $UserName -ErrorAction SilentlyContinue)) { Write-Host "User does not exist on this computer - skipped." $MissingUser++ continue } # Check if Leica backup exists if (-not (Test-Path $Source)) { Write-Host "No Leica backup found for this user." $MissingSource++ continue } try { Write-Host "Restoring Leica settings..." # Create target folder structure New-Item -ItemType Directory -Force -Path $Destination | Out-Null robocopy ` $Source ` $Destination ` /MIR ` /COPY:DAT ` /DCOPY:DAT ` /R:1 ` /W:1 $RC = $LASTEXITCODE if ($RC -lt 8) { Write-Host "Restore successful." $Copied++ } else { Write-Host "ERROR: Robocopy failed (ExitCode=$RC)" $Errors++ } } catch { Write-Host "ERROR: $($_.Exception.Message)" $Errors++ } } Write-Host "" Write-Host "========================================" Write-Host "Restore summary" Write-Host "========================================" Write-Host "Restored : $Copied" Write-Host "No backup found : $MissingSource" Write-Host "User missing : $MissingUser" Write-Host "Errors : $Errors" Write-Host "========================================" Stop-Transcript