简体   繁体   English

Powershell 2.0问题与从备份位置还原文件夹的脚本

[英]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.

相关问题 适用于多个文件夹的Powershell备份脚本 - Powershell Backup Script for multiple folders 需要一个Powershell脚本,该脚本会将文件夹和文件从一个位置移动到另一个位置 - Need a powershell script that will moved folders and files from a location to another location Powershell脚本备份7天以上的文件夹 - Powershell script to backup folders older than 7 days powershell脚本列出不包含最新备份文件的文件夹 - powershell script to list folders which do not contain a recent backup file PowerShell脚本将文件和文件夹(包括子文件夹)从一个位置移动到x天以外的另一个位置 - PowerShell script to move files and folders including subfolders from one location to another older than x days PowerShell - 以管理员身份运行时恢复脚本位置的目录 - PowerShell - Restore directory of script location while being ran as administrator Powershell脚本从列表中删除文件夹 - Powershell script to delete folders from list PowerShell脚本从文件和文件夹中删除字符 - PowerShell script to remove characters from files and folders PowerShell脚本从隐藏文件夹中删除文件 - PowerShell script to remove file from hidden folders Powershell 脚本从 Sharepoint 下载特定文件夹 - Powershell script to Download Specific folders from Sharepoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM