From 86813f37319d0063334192150f05de656e51c0e6 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:53:47 +0100 Subject: [PATCH] DISM cmdlet Update (Part 1) Began replacing basic DISM commands with cmdlets from the DISM module. This change only affects the mount, unmount, and export operations. All other operations still use DISM --- functions/public/Invoke-WPFMicrowin.ps1 | 20 ++++++++++++++------ winutil.ps1 | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index 8aa4d79a..6c8a2d6a 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -100,8 +100,16 @@ public class PowerManagement { try { Write-Host "Mounting Windows image. This may take a while." - dism /mount-image /imagefile:$mountDir\sources\install.wim /index:$index /mountdir:$scratchDir - Write-Host "Mounting complete! Performing removal of applications..." + Mount-WindowsImage -ImagePath "$mountDir\sources\install.wim" -Index $index -Path "$scratchDir" + if ($?) + { + Write-Host "Mounting complete! Performing removal of applications..." + } + else + { + Write-Host "Could not mount image. Exiting..." + return + } if ($injectDrivers) { @@ -299,13 +307,13 @@ public class PowerManagement { Write-Host "Cleanup complete." Write-Host "Unmounting image..." - dism /unmount-image /mountdir:$scratchDir /commit + Dismount-WindowsImage -Path $scratchDir -Save } try { Write-Host "Exporting image into $mountDir\sources\install2.wim" - dism /Export-Image /SourceImageFile:"$mountDir\sources\install.wim" /SourceIndex:$index /DestinationImageFile:"$mountDir\sources\install2.wim" /compress:max + Export-WindowsImage -SourceImagePath "$mountDir\sources\install.wim" -SourceIndex $index -DestinationImagePath "$mountDir\sources\install2.wim" -CompressionType "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" @@ -319,7 +327,7 @@ public class PowerManagement { # Next step boot image Write-Host "Mounting boot image $mountDir\sources\boot.wim into $scratchDir" - dism /mount-image /imagefile:"$mountDir\sources\boot.wim" /index:2 /mountdir:"$scratchDir" + Mount-WindowsImage -ImagePath "$mountDir\sources\boot.wim" -Index 2 -Path "$scratchDir" if ($injectDrivers) { @@ -365,7 +373,7 @@ public class PowerManagement { reg unload HKLM\zSYSTEM Write-Host "Unmounting image..." - dism /unmount-image /mountdir:$scratchDir /commit + Dismount-WindowsImage -Path $scratchDir -Save Write-Host "Creating ISO image" diff --git a/winutil.ps1 b/winutil.ps1 index 10b292ae..e4a02892 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -3536,8 +3536,16 @@ public class PowerManagement { try { Write-Host "Mounting Windows image. This may take a while." - dism /mount-image /imagefile:$mountDir\sources\install.wim /index:$index /mountdir:$scratchDir - Write-Host "Mounting complete! Performing removal of applications..." + Mount-WindowsImage -ImagePath "$mountDir\sources\install.wim" -Index $index -Path "$scratchDir" + if ($?) + { + Write-Host "Mounting complete! Performing removal of applications..." + } + else + { + Write-Host "Could not mount image. Exiting..." + return + } if ($injectDrivers) { @@ -3735,13 +3743,13 @@ public class PowerManagement { Write-Host "Cleanup complete." Write-Host "Unmounting image..." - dism /unmount-image /mountdir:$scratchDir /commit + Dismount-WindowsImage -Path $scratchDir -Save } try { Write-Host "Exporting image into $mountDir\sources\install2.wim" - dism /Export-Image /SourceImageFile:"$mountDir\sources\install.wim" /SourceIndex:$index /DestinationImageFile:"$mountDir\sources\install2.wim" /compress:max + Export-WindowsImage -SourceImagePath "$mountDir\sources\install.wim" -SourceIndex $index -DestinationImagePath "$mountDir\sources\install2.wim" -CompressionType "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" @@ -3755,7 +3763,7 @@ public class PowerManagement { # Next step boot image Write-Host "Mounting boot image $mountDir\sources\boot.wim into $scratchDir" - dism /mount-image /imagefile:"$mountDir\sources\boot.wim" /index:2 /mountdir:"$scratchDir" + Mount-WindowsImage -ImagePath "$mountDir\sources\boot.wim" -Index 2 -Path "$scratchDir" if ($injectDrivers) { @@ -3801,7 +3809,7 @@ public class PowerManagement { reg unload HKLM\zSYSTEM Write-Host "Unmounting image..." - dism /unmount-image /mountdir:$scratchDir /commit + Dismount-WindowsImage -Path $scratchDir -Save Write-Host "Creating ISO image"