简体   繁体   English

Powershell还原文件的先前版本

[英]Powershell restore previous version of the files

We got hit by virus, it changed all common file extension to .kmybamf (.txt >> .txt.kmybamf ) and if I delete .kmybamf , the file got damaged..... 我们被病毒击中,它将所有常用文件扩展名更改为.kmybamf(.txt >> .txt.kmybamf),如果我删除了.kmybamf,则文件损坏了.....

So I made a list of all files that got damaged. 因此,我列出了所有损坏的文件。 now I'm trying to overwrite them by previous version. 现在,我试图用以前的版本覆盖它们。 Anyone knows how to do it in Powershell? 有人知道如何在Powershell中执行此操作吗?

I can do it in cmd similar to this 我可以在cmd中做到这一点

subst X: \localhost\D$\@GMT-2011.09.20-06.00.04_Data
robocopy Z: D:\Folder\ /E /COPYALL

But I want to do it in one shot in Powershell, It has to be a "if .kmybamf found, then restore previous version." 但是我想在Powershell中一次完成它,它必须是“如果找到.kmybamf,然后还原以前的版本”。 and powershell seems like has no such cmdlet for restoring previous version of files or folders. Powershell似乎没有用于还原文件或文件夹先前版本的cmdlet。

$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
}

This will also work but I find it less readable 这也可以工作,但我发现它的可读性较差

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM