[英]Powershell 2.0 Issue with script to Restore folders from backup location
I have a backup Folder F:\\DATA\\01172014 - this folder has five sub dirs \\Folder1, \\Folder2, Folder3, Folder4, Folder5 我有一个备份文件夹F:\\ DATA \\ 01172014-该文件夹有五个子目录\\ Folder1,\\ Folder2,Folder3,Folder4,Folder5
F:\\DATA\\01172014.. ..\\Folder1 ..\\Folder2 ..\\Folder3 ..\\Folder4 ..\\Folder5 F:\\ DATA \\ 01172014 .. .. \\ Folder1 .. \\ Folder2 .. \\ Folder3 .. \\ Folder4 .. \\ Folder5
I want to copy the the folders 1 through 5 to the E:\\Main location overwriting the existing folders 我要将文件夹1到5复制到E:\\ Main位置,以覆盖现有文件夹
E:\\Main ..\\Folder1 ..\\Folder2 ..\\Folder3 ..\\Folder4 ..\\Folder5 E:\\ Main .. \\ Folder1 .. \\ Folder2 .. \\ Folder3 .. \\ Folder4 .. \\ Folder5
My problem is when I run the script it finds the 01172014 folder and copy's it to the E:\\Main as the same name and does not overwrite the old folders 我的问题是,当我运行脚本时,它会找到01172014文件夹并将其复制到E:\\ Main作为相同的名称,并且不会覆盖旧文件夹
E:\\Main ..\\01172014 ..\\Folder1 ..\\Folder2 ..\\Folder3 \\Folder4 ..\\Folder5 E:\\ Main .. \\ 01172014 .. \\ Folder1 .. \\ Folder2 .. \\ Folder3 \\ Folder4 .. \\ Folder5
My question is what am I missing 我的问题是我想念什么
Here is my code I am using :- 这是我正在使用的代码:
Get-ChildItem -Path F:\DATA -r |
Where-object {$_.PSIscontainer -and (($_.lastwritetime.date -eq ((get-date).adddays(-1)).date))} |
% { Copy-Item $_.fullName -destination E:\Main\ -force -R -whatif}
You're telling it to copy the date-stamped folder and contents, and it is. 您要告诉它复制带有日期戳的文件夹和内容,事实就是如此。
Try something like this instead which will copy the contents of the date-stamped folder and its sub-folders, but not the folder itself ( -Container
switch retains the structure): 尝试使用类似的方法,它将复制带日期标记的文件夹及其子文件夹的内容,但不复制文件夹本身(
-Container
开关保留结构):
$BackupDir = Get-ChildItem ("F:\DATA\" + (((get-date).AddDays(-1).ToString("MMddyyyy"))))|%{$_.FullName}
Copy-Item $BackupDir -Destination ("E:\Main\" + (Split-Path $BackupDir -leaf)) -R -Container -Force -WhatIf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.