Powershell恢复以前版本的文件

时间:2015-03-09 16:00:46

标签: powershell restore

我们受到了病毒的攻击,它将所有常见的文件扩展名更改为.kmybamf(.txt>> .txt.kmybamf),如果我删除.kmybamf,则该文件已损坏.....

所以我列出了所有损坏的文件。现在我试图用以前的版本覆盖它们。任何人都知道如何在Powershell中做到这一点?

我可以在类似于此

的cmd中完成
subst X: \localhost\D$\@GMT-2011.09.20-06.00.04_Data
robocopy Z: D:\Folder\ /E /COPYALL

但是我想在Powershell中一次性完成它,它必须是“if .kmybamf found,然后恢复以前的版本。”和PowerShell似乎没有这样的cmdlet来恢复以前版本的文件或文件夹。

2 个答案:

答案 0 :(得分:1)

$fileList = Get-Content -Path "\\localhost\D$\@GMT-2011.09.20-06.00.04_Data"
$destinationFolder = "D:\Folder\"

foreach ($file in $fileList)
{
    Copy-Item -Path $file -Destination $destinationFolder -Force
}

这也可以,但我觉得它不太可读

Get-Content -Path "\\localhost\D$\@GMT-2011.09.20-06.00.04_Data" | ForEach-Object { Copy-Item -Path $_ -Destination "D:\Folder" -Force }

答案 1 :(得分:0)

Get-Content用于从文件中读取文本,从您必须使用的文件夹中读取文件Get-Childitem