Files
douyi_guaji_main/tools/windows/dism_restorehealth_from_iso.ps1
T
CodexandClaude Opus 4.5 a19fa35a0f chore: 整理 tools/ 47 个脚本按功能分组
- diagnostics/ 11 个:环境/配置/依赖诊断
- logs/ 7 个:日志分析与查看
- coords/ 6 个:坐标拾取与区域选择
- cleanup/ 3 个:代码清理工具
- adb/ 2 个:ADB / 输入法相关
- windows/ 4 个:Windows 系统修复(备份)
- dev/ 9 个:开发辅助 / 运行时探测

并更新 tools/README.md 描述新结构。
删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。

tools/ 不被业务代码 import,分组仅为人工浏览方便。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-20 23:25:28 +08:00

88 lines
2.3 KiB
PowerShell

[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$IsoPath,
[int]$Index = 0,
[switch]$NoUnmount
)
$ErrorActionPreference = 'Stop'
function Write-Section([string]$title) {
Write-Host ""
Write-Host "=== $title ==="
}
function Test-IsAdmin {
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (!(Test-IsAdmin)) {
throw 'Please run this script as Administrator.'
}
$isoFull = (Resolve-Path $IsoPath).Path
if (!(Test-Path -LiteralPath $isoFull)) {
throw "ISO not found: $isoFull"
}
Write-Section 'Mount ISO'
Write-Host "ISO: $isoFull"
$disk = Mount-DiskImage -ImagePath $isoFull -PassThru
Start-Sleep -Seconds 1
$vol = ($disk | Get-Volume | Select-Object -First 1)
if ($null -eq $vol -or [string]::IsNullOrWhiteSpace($vol.DriveLetter)) {
throw 'Failed to get mounted ISO drive letter.'
}
$drive = ($vol.DriveLetter + ':')
Write-Host "Mounted drive: $drive"
try {
Write-Section 'Locate install.wim/install.esd'
$wim = Join-Path $drive 'sources\install.wim'
$esd = Join-Path $drive 'sources\install.esd'
$imagePath = $null
if (Test-Path -LiteralPath $wim) { $imagePath = $wim }
elseif (Test-Path -LiteralPath $esd) { $imagePath = $esd }
else { throw 'install.wim/install.esd not found under sources\\' }
Write-Host "Image: $imagePath"
Write-Section 'Show available indexes'
dism /English /Get-WimInfo /WimFile:"$imagePath"
if ($Index -le 0) {
Write-Host "\nIndex is 0: please re-run with -Index <number> matching your edition (e.g. Pro/Home)."
return
}
Write-Section 'DISM RestoreHealth (from ISO source)'
Write-Host "Using Index: $Index"
$sourceArg = if ($imagePath.ToLowerInvariant().EndsWith('.wim')) {
"wim:$imagePath:$Index"
} else {
"esd:$imagePath:$Index"
}
dism /Online /Cleanup-Image /RestoreHealth /Source:$sourceArg /LimitAccess
Write-Section 'SFC Scannow'
sfc /scannow
Write-Host '\nDone. Reboot recommended.'
}
finally {
if (-not $NoUnmount) {
Write-Section 'Unmount ISO'
Dismount-DiskImage -ImagePath $isoFull -ErrorAction SilentlyContinue
} else {
Write-Host 'NoUnmount set; ISO left mounted.'
}
}