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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| param (
# Use Generate Session URL function to obtain a value for -sessionUrl parameter.
$sessionUrl = "ftp://*****/",
#[Parameter(Mandatory = $True)]
$localPath0 = "$folderpath\OUTILS",
$localPath1 = "$folderpath\LENOVO TINY M73",
$localPath2 = "$folderpath\LENOVO M72e",
$localPath3 = "$folderpath\PRELOAD\HP6305",
$localPath4 = "$folderpath\PRELOAD\HP6005",
$localPath5 = "$folderpath\PRELOAD\HP705G2",
$localPath6 = "$folderpath\PRELOAD\HP705G1",
$localPath7 = "$folderpath\PRELOAD\HP_Z240",
$localPath8 = "$folderpath\MASTER\Tools_Master_SCCM",
$localPath9 = "$folderpath\MASTER\Procédure_Master_SCCM",
$localPath10 = "$folderpath\MASTER\FOLS\F10",
$localPath11 = "$folderpath\MASTER\FOLS\F7.4.X",
#$localPath12 = "$folderpath\MASTER\Application_Master_V1.4.docx",
#[Parameter(Mandatory = $True)]
$remotePath0 = "/MaintenanceIT/OUTILS/",
$remotePath1 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/LENOVO TINY M73/",
$remotePath2 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/LENOVO M72e/",
$remotePath3 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP6305/",
$remotePath4 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP6005/",
$remotePath5 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP705G2/",
$remotePath6 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP705G1/",
$remotePath7 = "/MaintenanceIT/PRELOAD/POSTE_FIXE/HP_Z240/",
$remotePath8 = "/MaintenanceIT/MASTER/Tools_Master_SCCM/",
$remotePath9 = "/MaintenanceIT/MASTER/Procédure_Master_SCCM/",
$remotePath10 = "/MaintenanceIT/MASTER/FOLS/F10/",
$remotePath11 = "/MaintenanceIT/MASTER/FOLS/F7.4.X/",
#$remotePath12 = "/MaintenanceIT/MASTER/Application_Master_V1.4.docx",
[Switch]
$delete,
[Switch]
$beep,
[Switch]
$continueOnError,
$sessionLogPath = "$folderpath\Log.txt",
$interval = 30,
[Switch]
$pause
)
Set-ExecutionPolicy Unrestricted -Scope Process -Force
#Déclaration de la Fonction : Select-Folder
function Select-Folder($message='Sélectionnez la destination', $path = 0)
{
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, $message, 0, $path)
if ($folder -ne $null)
{
$folder.self.Path
}
}
#Fin de la déclaration
#Appel de la Fonction pour afficher la boite de dialogue :
$folderpath=Select-Folder 'Veuillez choisir le répertoire de destination'
#Si vous souhaitez placer le parcours de dossier sur un répertoire par défaut, il suffit d'ajouter ce paramètre : -path "VOTRE CHEMIN"
#$folderpath=Select-Folder 'Selectionner un répertoire' -path "C:\Users"
#Variable pour récupérer le chemin du répertoire sélectionné
$folderpath
try
{
# Load WinSCP .NET assembly
$assemblyPath = if ($env:WINSCP_PATH) { $env:WINSCP_PATH } else { $PSScriptRoot }
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.ParseUrl($sessionUrl)
$session = New-Object WinSCP.Session
# Optimization
# (do not waste time enumerating files, if you do not need to scan for deleted files)
if ($delete)
{
$localFiles = Get-ChildItem -Recurse -Path $localPath
}
try
{
$session.SessionLogPath = $sessionLogPath
Write-Host "Connection..."
$session.Open($sessionOptions)
while ($True)
{
Write-Host "Synchronisation des dossiers..."
$result =
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath0, $remotePath0, $Delete).Check()
Write-Host "Synchronisation du dossier OUTILS ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath1, $remotePath1, $Delete).Check()
Write-Host "Synchronisation du dossier LENOVO TINY M73 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath2, $remotePath2, $Delete).Check()
Write-Host "Synchronisation du dossier LENOVO M72e ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath3, $remotePath3, $Delete).Check()
Write-Host "Synchronisation du dossier HP6305 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath4, $remotePath4, $Delete).Check()
Write-Host "Synchronisation du dossier HP6005 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath5, $remotePath5, $Delete).Check()
Write-Host "Synchronisation du dossier HP705G2 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath6, $remotePath6, $Delete).Check()
Write-Host "Synchronisation du dossier HP705G1 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath7, $remotePath7, $Delete).Check()
Write-Host "Synchronisation du dossier HP_Z240 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath8, $remotePath8, $Delete).Check()
Write-Host "Synchronisation du dossier Tools_Master_SCCM ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath9, $remotePath9, $Delete).Check()
Write-Host "Synchronisation du dossier Procédure_Master_SCCM ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath10, $remotePath10, $Delete).Check()
Write-Host "Synchronisation du dossier MASTER/FOLS/F10 ...OK",
$session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath11, $remotePath11, $Delete).Check()
Write-Host "Synchronisation du dossier MASTER/FOLS/F7.4.X ...OK",
#$session.SynchronizeDirectories(
#[WinSCP.SynchronizationMode]::Local, $localPath12, $remotePath12, $Delete).Check(),
$changed = $False
if (!$result.IsSuccess)
{
if ($continueOnError)
{
Write-Host "Erreur: $($result.Failures[0].Message)"
$changed = $True
}
}
# Print updated files
foreach ($download in $result.Downloads)
{
Write-Host "$($download.Destination) <= $($download.FileName)"
$changed = $True
}
if ($delete)
{
# scan for removed local files (the $result does not include them)
$localFiles2 = Get-ChildItem -Recurse -Path $localPath
if ($localFiles)
{
$changes =
Compare-Object -DifferenceObject $localFiles2 `
-ReferenceObject $localFiles
$removedFiles =
$changes |
Where-Object -FilterScript { $_.SideIndicator -eq "<=" } |
Select-Object -ExpandProperty InputObject
# Print removed local files
foreach ($removedFile in $removedFiles)
{
Write-Host "$removedFile deleted"
$changed = $True
}
}
$localFiles = $localFiles2
}
if ($changed)
{
if ($beep)
{
[System.Console]::Beep()
}
}
else
{
Write-Host "Pas de changement."
}
Write-Host "Patientez $interval secondes ou pressez Ctrl+C pour annuler..."
$wait = [int]$interval
# Wait for 1 second in a loop, to make the waiting breakable
while ($wait -gt 0)
{
Start-Sleep -Seconds 1
$wait--
}
Write-Host
}
}
finally
{
Write-Host "Déconnection..."
# Disconnect, clean up
$session.Dispose()
}
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
}
# Never exits cleanly
exit 1 |