2017-06-21 23 views
0

複製要從源頭我如何的文件夾結構僅使用PowerShell

我知道,我的代碼將複製文件的過程複製的文件夾結構(不使用數據),並保留ACL。

$sourceDir = "\\Server\Path" 
$targetDir = "\\Server2\Path" 
Get-ChildItem -Path $sourceDir | Copy-Item -Destination $targetDir -Recurse -Container 

在我們的組織中不允許使用robocopy和xcopy。我不知道爲什麼,但事實並非如此。我寧願不使用GUI來手動創建文件夾/子文件夾。

+2

你是什麼意思 「ROBOCOPY是不允許的」 呢?這是一個Windows內置工具。什麼是不允許的? –

回答

1

使用-Filter {PSIsContainer}只會複製目錄:

$sourceDir = "\\Server\Path" 
$targetDir = "\\Server2\Path" 
Copy-Item $sourceDir $targetDir -Filter {PSIsContainer} -Recurse -Force 
相關問題