2015-05-14 74 views
0

我想創建一個連接到網絡驅動器的Powershell腳本,然後將遠程文件與本地文件進行比較。如果遠程目標(共享驅動器上)的文件較新,則將其複製到本地目標。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} 

我得到以下輸出

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

File Not Found 

Invalid Number of Parameters 

回答

0

由於$folders不是一個數組,爲什麼的foreach?爲什麼不只是

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

或者是實際的代碼與示例不同?