PS1 Betiği : Geri Dönüşüm Kutusu Bozuk Hatasının Hakkından Gelir...

Programlama ve Script dilleri konusunda bilgi paylaşım alanıdır.
Cevapla
Kullanıcı avatarı
TRWE_2012
Zettabyte1
Zettabyte1
Mesajlar: 15612
Kayıt: 25 Eyl 2013, 13:38
cinsiyet: Erkek
Teşekkür etti: 2710 kez
Teşekkür edildi: 5626 kez

PS1 Betiği : Geri Dönüşüm Kutusu Bozuk Hatasının Hakkından Gelir...

Mesaj gönderen TRWE_2012 »

Merhabalar

https://www.sordum.net/39960/geri-donus ... ve-cozumu/ makalesindeki CMD versiyonun .PS1 versiyonudur.
Resim
KOD İÇERİĞİ : (recycle_bin_repair.ps1)

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."
KOD İÇERİK AÇIKLAMASI :
Resim
Gerektiğinde kullanın güle güle kullanın...
Kullanıcı avatarı
velociraptor
Yottabyte4
Yottabyte4
Mesajlar: 54872
Kayıt: 14 Mar 2006, 02:33
cinsiyet: Erkek
Teşekkür etti: 21124 kez
Teşekkür edildi: 12486 kez

Re: PS1 Betiği : Geri Dönüşüm Kutusu Bozuk Hatasının Hakkından Gelir...

Mesaj gönderen velociraptor »

Eline sağlık
Cevapla

“Programlama ve Script dilleri” sayfasına dön