Powershell脚本将远程路径上的文件与本地路径进行比较,如果是新的话,将其复制到本地路径

时间:2015-05-14 10:14:57

标签: powershell scripting

我想创建一个连接到网络驱动器的Powershell脚本,然后将远程文件与本地文件进行比较。如果远程目标上的文件(在共享驱动器上)较新,则将其复制到本地目标。

以下是我使用的代码。

net use Y:

if ($LastExitCode -ne 0)

{
    net use Y: Path
}

$folders = @{local = 'Local Path';remote='Remote Path'},

$folders | Foreach {xcopy $_.remote $_.local /S /C /Y /D /I}

我得到以下OutPut

Local Name Y:
Remote Name \\Path of the shared drive
Resource Type Disk
The command Completed Sucessfully

File Not Found

Invalid Number of Parameters 

1 个答案:

答案 0 :(得分:0)

由于$folders不是数组,为什么要使用Foreach?为什么不呢

$folders = @{local = 'Local Path';remote='Remote Path'},
xcopy $folders.remote $folders.local /S /C /Y /D /I

或者实际代码与示例有什么不同?