diff --git a/functions/microwin/Invoke-Microwin.ps1 b/functions/microwin/Invoke-Microwin.ps1 index c6357e8a..7cb44b0a 100644 --- a/functions/microwin/Invoke-Microwin.ps1 +++ b/functions/microwin/Invoke-Microwin.ps1 @@ -63,7 +63,14 @@ public class PowerManagement { # 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)) { 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..." - Export-WindowsImage -SourceImagePath $mountDir\sources\install.esd -SourceIndex $index -DestinationImagePath $mountDir\sources\install.wim -CompressionType "Max" + try { + # Try ps command first + 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 ($?) { Remove-Item -Path "$mountDir\sources\install.esd" -Force # Since we've already exported the image index we wanted, switch to the first one @@ -360,7 +367,14 @@ public class PowerManagement { try { Write-Host "Exporting image into $mountDir\sources\install2.wim" - Export-WindowsImage -SourceImagePath "$mountDir\sources\install.wim" -SourceIndex $index -DestinationImagePath "$mountDir\sources\install2.wim" -CompressionType "Max" + try { + # Try ps command first + 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" Remove-Item "$mountDir\sources\install.wim" Rename-Item "$mountDir\sources\install2.wim" "$mountDir\sources\install.wim"