function Undo-LastDelete <# .SYNOPSIS Restores files from Recycle Bin (undo for del/Remove-Item) .EXAMPLE Undo-LastDelete -Last 5 #> param([int]$Last = 1) Add-Type -AssemblyName Microsoft.VisualBasic $shell = New-Object -ComObject Shell.Application $recycleBin = $shell.NameSpace(0x0a)
For text/files, use Git :
However, here's a using PowerShell's -WhatIf and reusable functions: Best Practice: Preview Before Running # In PowerShell — preview destructive commands first Remove-Item .\file.txt -WhatIf Custom PowerShell "Undo" Function (Undelete) Save this function in your PowerShell profile: windows command for undo