Halloween is upon us and the Chairman has devised a demonic PowerShell scripting challenge for you. This is not for the faint of heart. The Chairman wants you to raise the dead. Specifically, deleted items in your Recycle Bin on a Windows 10 desktop. There are several parts to this challenge.
First, calculate how much space is being used by files in the recycle bin. At least based on the detected file size. This value may be different than what Windows reports in Settings or with other tools. And if you have multiple drives don’t forget to take that into account. The second part of the challenge is to write PowerShell code to move a file from the recycle bin back to its original location and name.
You are welcome to use any approach you’d like. The Recycle Bin can be accessed as a hidden directory like C:\$Recycle.Bin but it’s behavior is a bit different than a typical file system folder. Still, that is a possibility for the first part of the challenge. However, for the second part of the challenge you will need to discover the original filename and location.
One possible approach is to use the Shell.Application COM object.
$shell = New-Object -com shell.application $rb = $shell.Namespace(10) $rb.items()
Of course, you’ll need to take deleted folder structures into account.
You are welcome to use any approach you want. The Shell.Application is merely a suggestion for people who have no idea on where to even begin.
As always, please don’t submit any solutions in the comments. Links to your work are always welcome. Halloween is almost upon us and the dead won’t wait so you’d better get to it!