如何仅使用PowerShell复制文件夹结构

时间:2017-06-21 14:28:52

标签: powershell powershell-v5.0

我想仅复制文件夹结构(无数据)并保留源

的ACL

我知道我的代码会复制文件。

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

我们的组织不允许使用robocopy和xcopy。我不知道为什么,但事实并非如此。我宁愿不使用GUI来手动创建文件夹/子文件夹。

1 个答案:

答案 0 :(得分:1)

使用-Filter {PSIsContainer}只能复制目录:

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