I have some issue with Sync center on my computer since I upgrade it to W10, so I try to write an alternative script that compare the sync folders/files on a desktop and our ServerFiles and copy the latest version of each folders/files on the user computer.
Thanks to the community I found some code, but it's doesnt work well for me
I'm a newbie on scripting with powershell 5.1. Im working with a WS2008 and the desktop on W10.
$SourceFolder = Get-ChildItem -Recurse "\\Srvfiles\USERS\user1\"
#"user1" contains 2 folders and each one have subfolders/files
$TargetFolder = Get-ChildItem "D:\Doc_Sync"
$Result = Compare-Object $SourceFolder $TargetFolder -Property Name, Length
foreach ($folder in $Result) {
if ($folder.SideIndicator -eq "<=") {
$FullSourceObject = $folder.InputObject.FullName
$FullTargetObject = $folder.InputObject.FullName.Replace($SourceFolder, $TargetFolder)
Copy-Item "\\Srvfiles\USERS\user1\$($_.name)" -Destination $Get-ChildItem "D:\Doc_Sync" -Recurse -Force
}
}
The good new is it working for somes folders, on D:/Doc_Sync it paste most of the files but(bad new), for the rest of them , I got many error :
Cannot bind argument to parameter « DifferenceObject » because it is null.
At line:5 char:40
+ $Result = Compare-Object $SourceFolder $TargetFolder -Property Name, ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData : (:) [Compare-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
You cannot call a method on a null-valued expression.
At line:10 char:13
+ $FullTargetObject = $folder.InputObject.FullName.Replace( ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Thanks for your futur help