RepairWindows.psm1

function RepairWin {
    [CmdletBinding()]
    param ()

    function Run-Command {
        param (
            [string]$Command,
            [string]$Description
        )

        Write-Output "Running: $Description"
        try {
            Invoke-Expression $Command
            Write-Output "Success: $Description"
        } catch {
            Write-Error "Failed: $Description"
        }
    }

    # Check if running as admin
    if (-not ([bool](New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
        Write-Error "This script must be run as an administrator."
        exit 1
    }

    # Run DISM command
    Run-Command -Command "DISM /Online /Cleanup-Image /RestoreHealth" -Description "Restore health of Windows image"

    # Run SFC command twice
    for ($i = 1; $i -le 2; $i++) {
        Run-Command -Command "sfc /scannow" -Description "System File Checker (SFC) scan ($i)"
    }
}