mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-05-10 00:02:09 +00:00
Fix: Add DISM fallback for Export-WindowsImage errors (#3224)
This commit is contained in:
parent
84a18503b8
commit
4ec23f76a8
@ -63,7 +63,14 @@ public class PowerManagement {
|
|||||||
# Detect if the Windows image is an ESD file and convert it to WIM
|
# Detect if the Windows image is an ESD file and convert it to WIM
|
||||||
if (-not (Test-Path -Path "$mountDir\sources\install.wim" -PathType Leaf) -and (Test-Path -Path "$mountDir\sources\install.esd" -PathType Leaf)) {
|
if (-not (Test-Path -Path "$mountDir\sources\install.wim" -PathType Leaf) -and (Test-Path -Path "$mountDir\sources\install.esd" -PathType Leaf)) {
|
||||||
Write-Host "Exporting Windows image to a WIM file, keeping the index we want to work on. This can take several minutes, depending on the performance of your computer..."
|
Write-Host "Exporting Windows image to a WIM file, keeping the index we want to work on. This can take several minutes, depending on the performance of your computer..."
|
||||||
|
try {
|
||||||
|
# Try ps command first
|
||||||
Export-WindowsImage -SourceImagePath $mountDir\sources\install.esd -SourceIndex $index -DestinationImagePath $mountDir\sources\install.wim -CompressionType "Max"
|
Export-WindowsImage -SourceImagePath $mountDir\sources\install.esd -SourceIndex $index -DestinationImagePath $mountDir\sources\install.wim -CompressionType "Max"
|
||||||
|
} catch {
|
||||||
|
# Fallback to DISM command
|
||||||
|
Write-Host "Export-WindowsImage failed, using DISM instead..."
|
||||||
|
dism /Export-Image /SourceImageFile:$mountDir\sources\install.esd /SourceIndex:$index /DestinationImageFile:$mountDir\sources\install.wim /Compress:max
|
||||||
|
}
|
||||||
if ($?) {
|
if ($?) {
|
||||||
Remove-Item -Path "$mountDir\sources\install.esd" -Force
|
Remove-Item -Path "$mountDir\sources\install.esd" -Force
|
||||||
# Since we've already exported the image index we wanted, switch to the first one
|
# Since we've already exported the image index we wanted, switch to the first one
|
||||||
@ -360,7 +367,14 @@ public class PowerManagement {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
Write-Host "Exporting image into $mountDir\sources\install2.wim"
|
Write-Host "Exporting image into $mountDir\sources\install2.wim"
|
||||||
|
try {
|
||||||
|
# Try ps command first
|
||||||
Export-WindowsImage -SourceImagePath "$mountDir\sources\install.wim" -SourceIndex $index -DestinationImagePath "$mountDir\sources\install2.wim" -CompressionType "Max"
|
Export-WindowsImage -SourceImagePath "$mountDir\sources\install.wim" -SourceIndex $index -DestinationImagePath "$mountDir\sources\install2.wim" -CompressionType "Max"
|
||||||
|
} catch {
|
||||||
|
# Fallback to DISM command
|
||||||
|
Write-Host "Export-WindowsImage failed, using DISM instead..."
|
||||||
|
dism /Export-Image /SourceImageFile:"$mountDir\sources\install.wim" /SourceIndex:$index /DestinationImageFile:"$mountDir\sources\install2.wim" /Compress:max
|
||||||
|
}
|
||||||
Write-Host "Remove old '$mountDir\sources\install.wim' and rename $mountDir\sources\install2.wim"
|
Write-Host "Remove old '$mountDir\sources\install.wim' and rename $mountDir\sources\install2.wim"
|
||||||
Remove-Item "$mountDir\sources\install.wim"
|
Remove-Item "$mountDir\sources\install.wim"
|
||||||
Rename-Item "$mountDir\sources\install2.wim" "$mountDir\sources\install.wim"
|
Rename-Item "$mountDir\sources\install2.wim" "$mountDir\sources\install.wim"
|
||||||
|
Loading…
Reference in New Issue
Block a user