【问题标题】:how to copy folder structure only with PowerShell如何仅使用 PowerShell 复制文件夹结构
【发布时间】:2017-11-24 12:38:34
【问题描述】:

我只想复制文件夹结构(无数据)并保留来自源的 ACL

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

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

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

【问题讨论】:

  • 你说的“robocopy 是不允许的”是什么意思?它是 Windows 内置工具。这有什么不被允许的?

标签: powershell powershell-5.0


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    相关资源
    最近更新 更多