Set-ExecutionPolicy -Scope LocalMachine Unrestricted -Force clear $users = Get-LocalUser | Select-Object -ExpandProperty Name $user = $env:USERNAME $docSauv = "C:\Sauvegarde\$user\Documents\*" $picSauv = "C:\Sauvegarde\$user\Pictures\*" if (Test-Path $docSauv) { $contenudoc = Get-ChildItem -Path $docSauv -Recurse -ErrorAction SilentlyContinue if ($contenudoc) { $destinationDoc = [Environment]::GetFolderPath("MyDocuments") Copy-Item -Path $docSauv -Destination $destinationDoc -Recurse -Force -ErrorAction SilentlyContinue } } if (Test-Path $picSauv) { $contenupic = Get-ChildItem -Path $picSauv -Recurse -ErrorAction SilentlyContinue if ($contenupic) { $destinationPic = [Environment]::GetFolderPath("MyPictures") Copy-Item -Path $picSauv -Destination $destinationPic -Recurse -Force -ErrorAction SilentlyContinue } } *************************************************************************************************************************************************************************************# Assurez-vous d'avoir le module PSFTP installé et importé Install-Module -Name PSFTP -Force Import-Module -Name PSFTP Set-ExecutionPolicy -Scope LocalMachine Unrestricted -Force clear # Détails du serveur FTP $ftpServer = "ftp://votre_serveur_ftp.com" # Remplacez par l'adresse de votre serveur FTP $ftpUser = "votre_utilisateur" # Remplacez par votre nom d'utilisateur FTP $ftpPassword = "votre_mot_de_passe" # Remplacez par votre mot de passe FTP # Fonction pour télécharger des fichiers depuis le serveur FTP function Get-FromFtp { param ( [string]$ftpPath, [string]$localPath ) $session = New-FTPConnection -Server $ftpServer -Credentials (New-Object -TypeName PSCredential -ArgumentList $ftpUser, (ConvertTo-SecureString -String $ftpPassword -AsPlainText -Force)) Get-FTPItem -Session $session -RemotePath $ftpPath -LocalPath $localPath -Recurse -Force Remove-FTPConnection -Session $session } # Variables utilisateur et chemins des fichiers $users = Get-LocalUser | Select-Object -ExpandProperty Name $user = $env:USERNAME # Chemins sur le serveur FTP $ftpDocumentsPath = "/Sauvegarde/$user/Documents" $ftpPicturesPath = "/Sauvegarde/$user/Pictures" # Dossiers locaux des utilisateurs $localDocumentsPath = [Environment]::GetFolderPath("MyDocuments") $localPicturesPath = [Environment]::GetFolderPath("MyPictures") # Télécharger les documents depuis le serveur FTP if (Test-Path $ftpDocumentsPath) { Get-FromFtp -ftpPath $ftpDocumentsPath -localPath $localDocumentsPath } # Télécharger les images depuis le serveur FTP if (Test-Path $ftpPicturesPath) { Get-FromFtp -ftpPath $ftpPicturesPath -localPath $localPicturesPath }