[英]How to copy folders and files from RDP server to local computer with Powershell
[英]How can I sync Folders from a Serverfile to a client computer with powershell?
我的计算机上的同步中心有一些问题,因为我将其升级到W10,所以我尝试编写一个替代脚本,比较桌面上的同步文件夹/文件和我们的ServerFiles,并复制每个文件夹/文件的最新版本。用户电脑。
感谢社区,我发现了一些代码,但它对我来说并不好用
我是PowerShell 5.1脚本的新手。 我在W10上使用WS2008和桌面。
$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
}
}
好新的是它适用于某些文件夹,在D:/ Doc_Sync上它粘贴大部分文件但是(坏的新文件),对于其余的文件,我收到了很多错误:
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
感谢您的未来帮助
由于断点,我发现第一个错误有什么问题。 我改变了$ TargetFolder,如下所示:
$TargetFolder = @(Get-ChildItem -Recurse "D:\Doc_Sync")
但我仍然有“$ FullTargetObject”的第二个错误。 我觉得这条线路有什么问题......本周末我会继续努力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.