$FSys=@{} $Root = '\\sorgente\share\cartella' $FDest = '\\destinazione\share\cartella' $logpath='\\logserver\Log\' $Table=,@{} $strdest=$root -replace '\\' , '-' $strdest=$FDest -replace ':','-' $logname= $logpath + "{0:yyyyMMdd-HHmm}.log" -f (Get-Date) (New-Object -ComObject WScript.Network).MapNetworkDrive("y:",$FDest) $Tree= Get-ChildItem $Root -recurse | Sort-Object -property @{Expression="Attributes";Descending=$false},@{Expression="Fullname";Descending=$false} foreach ($Item in $Tree) { #Replace illegal characters with legal characters where found $newFileName = $item.Fullname #These characters may be used on the file system but not SharePoint $newFileName = ($newFileName -replace "&", "and") $newFileName = ($newFileName -replace "{", "(") $newFileName = ($newFileName -replace "}", ")") $newFileName = ($newFileName -replace "~", "-") $newFileName = ($newFileName -replace "#", "") $newFileName = ($newFileName -replace "%", "") #Check for start, end and double periods $newFileName = $newFileName.TrimStart(".") $newFileName = $newFileName.TrimEnd(".") $newFileName = $newFileName.Replace("..", ".") $FSys.PATH=$Item.FullName $FSys.ATTR=$Item.Attributes $FSys.LWTime=$Item.Lastwritetime $FSys.NEW=($newFileName -replace [regex]::escape($Root), $FDest) $FSys.NCP="" $Node=New-Object PSObject -Property $Fsys $Table += $Node $FSys.NCP="N" if (!(Test-Path -path $FSys.NEW)) { if ($Item -is [System.IO.DirectoryInfo] ) { New-Item $FSys.NEW -type directory (Get-Item $FSys.NEW).lastWriteTime = $FSys.LWTime $FSys.NCP="Y" } else { Copy-Item $FSys.PATH -Destination $FSys.NEW } } else {$FSys.PATH} } write-output $Table| Format-Table @{Expression={$_.PATH};Label="SORGENTE"},@{Expression={$_.ATTR};Label="ATTRIBUTI"} ,@{Expression={$_.LWTime};Label="MODIFICATO"},@{Expression={$_.New};Label="DESTINAZIONE"},@{Expression={$_.NCP};Label="NEW"} -auto | out-file $logname -Width 5120 (new-object -com WScript.Network).RemoveNetworkDrive("y:")