[英]How can Powershell copy an entire folder structure but exclude one folder and its contents
[英]powershell copy all folder structure and exclude one or more folders
我正在尝试使用PowerShell将包含子文件夹的文件夹从我们的用户复制到小型备份中。 这些文件夹包含一个我不想复制的名为“ windows”的文件夹。
我尝试过“排除”,但似乎无法使其正常工作。 到目前为止,这是脚本:
Copy-Item "E:\Curos folder" -Exclude 'Windows' -Destination "E:\Curos folder backup" -Recurse -Verbose
我看过其他帖子,但不安静地了解它的工作原理
这是我第一次使用PowerShell
我会用这样的东西:
Get-ChildItem $root -Directory -Recurse | % {$_.name -ne 'Windows'} | foreach {Copy-Item "$($_.FullName)" -Destination $dest -Recurse}
我尚未对其进行测试,但这是您应该能够进行工作的基础,尽管我没有发现在Get-ChildItem和Copy-Item上都使用递归的意义,我的建议是在Get- ChildItem。
你是完全正确的。 实际上,该脚本比我之前编写的脚本更简单。 开始了:
$source = "C:\Users\gaston.gonzalez\Documents\02_Scripts"
$destination = "D:\To Delete"
$exclude = "Windows"
$folders = Get-ChildItem -Path $source | Where {($_.PSIsContainer) -and ($exclude -notcontains $_.Name)}
foreach ($f in $folders){
Write-Host "This folders will be copied: $f"
Copy-Item -Path $source\$f -Destination $destination\$f -Recurse -Force
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.