https://www.sordum.net/39960/geri-donus ... ve-cozumu/ makalesindeki CMD versiyonun .PS1 versiyonudur.

Kod: Tümünü seç
# Recycle Bin Repair Tool
# Purpose: removes a corrupted $Recycle.bin folder on a chosen drive so that
# Windows can automatically recreate a clean, working Recycle Bin for that drive.
# Compatible with Windows PowerShell 5.1 and PowerShell 7.x.
# --- Self-elevation ---
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Administrator privileges are required. Restarting with elevation..."
$scriptPath = $MyInvocation.MyCommand.Path
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "`"$scriptPath`"" -Verb RunAs
exit
}
Write-Host "================================================="
Write-Host " Recycle Bin Repair Tool"
Write-Host "================================================="
Write-Host ""
Write-Host "This tool removes the hidden `$Recycle.bin folder on a chosen drive."
Write-Host "Windows will automatically recreate an empty, working Recycle Bin"
Write-Host "for that drive the next time it is needed."
Write-Host ""
$continue = $true
while ($continue) {
$driveInput = Read-Host "Enter the drive letter showing the error (example: C)"
$driveLetter = $driveInput.Trim().TrimEnd(":").ToUpper()
if ($driveLetter -notmatch '^[A-Z]$') {
Write-Host "Invalid input. Please enter a single drive letter, for example: C" -ForegroundColor Yellow
}
else {
$driveRoot = "$driveLetter" + ":\"
if (-not (Test-Path -LiteralPath $driveRoot)) {
Write-Host "Drive $driveLetter`: was not found on this system." -ForegroundColor Red
}
else {
$targetPath = "$driveLetter" + ':\$Recycle.bin'
Write-Host ""
Write-Host "Target folder: $targetPath"
if (-not (Test-Path -LiteralPath $targetPath)) {
Write-Host "No `$Recycle.bin folder was found on drive $driveLetter`:. Nothing to repair." -ForegroundColor Yellow
}
else {
Write-Host "Attempting to remove the folder..."
$success = $false
try {
Remove-Item -LiteralPath $targetPath -Recurse -Force -ErrorAction Stop
$success = $true
}
catch {
Write-Host "Standard removal failed: $($_.Exception.Message)" -ForegroundColor Yellow
Write-Host "Trying to reset ownership and permissions before retrying..."
try {
takeown.exe /F $targetPath /R /D Y | Out-Null
icacls.exe $targetPath /grant "Administrators:F" /T /C | Out-Null
Remove-Item -LiteralPath $targetPath -Recurse -Force -ErrorAction Stop
$success = $true
}
catch {
Write-Host "Second attempt failed: $($_.Exception.Message)" -ForegroundColor Red
}
}
if ($success) {
Write-Host "The Recycle Bin folder on drive $driveLetter`: was removed successfully." -ForegroundColor Green
Write-Host "Windows will recreate a clean Recycle Bin for this drive automatically."
}
else {
Write-Host "The repair could not be completed automatically." -ForegroundColor Red
Write-Host "Close any programs or Explorer windows that may be using this drive,"
Write-Host "then either run this tool again or restart the computer and try once more."
}
}
}
}
Write-Host ""
$again = Read-Host "Do you want to repair another drive? (Y/N)"
if ($again.Trim().ToUpper() -ne "Y") {
$continue = $false
}
Write-Host ""
}
Read-Host "`nPress ENTER to exit."



