From bba078c34bd2108188a09653ea1de32edffe7a93 Mon Sep 17 00:00:00 2001 From: Karl Wester-Ebbinghaus <45657752+Karl-WE@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:25:16 +0100 Subject: [PATCH] Update tiny11maker.ps1 - use dism with PowerShell commands The idea of the release of this project is using PowerShell instead of commandline in the previous version, which is a great move and make it easier to maintain and read. For sake of easier syntax and readability I have attempted using PowerShell commandlets for dism. There are few remaining areas that need to be reworked (invoking dism.exe) to become fully consistent. --- tiny11maker.ps1 | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tiny11maker.ps1 b/tiny11maker.ps1 index 7ef954d..f115e6e 100644 --- a/tiny11maker.ps1 +++ b/tiny11maker.ps1 @@ -49,12 +49,12 @@ $DriveLetter = $DriveLetter + ":" if ((Test-Path "$DriveLetter\sources\boot.wim") -eq $false -or (Test-Path "$DriveLetter\sources\install.wim") -eq $false) { if ((Test-Path "$DriveLetter\sources\install.esd") -eq $true) { Write-Host "Found install.esd, converting to install.wim..." - & 'dism' '/English' "/Get-WimInfo" "/wimfile:$DriveLetter\sources\install.esd" + Get-WindowsImage -ImagePath $DriveLetter\sources\install.esd $index = Read-Host "Please enter the image index" Write-Host ' ' Write-Host 'Converting install.esd to install.wim. This may take a while...' - & 'DISM' /Export-Image /SourceImageFile:"$DriveLetter\sources\install.esd" /SourceIndex:$index /DestinationImageFile:"$ScratchDisk\tiny11\sources\install.wim" /Compress:max /CheckIntegrity - } else { + Export-WindowsImage -SourceImagePath $DriveLetter\sources\install.esd -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install.wim -Compressiontype Maximum -CheckIntegrity + } else { Write-Host "Can't find Windows OS Installation files in the specified Drive Letter.." Write-Host "Please enter the correct DVD Drive Letter.." exit @@ -69,10 +69,10 @@ Write-Host "Copy complete!" Start-Sleep -Seconds 2 Clear-Host Write-Host "Getting image information:" -& 'dism' '/English' "/Get-WimInfo" "/wimfile:$ScratchDisk\tiny11\sources\install.wim" +Get-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\install.wim $index = Read-Host "Please enter the image index" Write-Host "Mounting Windows image. This may take a while." -$wimFilePath = "$($env:SystemDrive)\tiny11\sources\install.wim" +$wimFilePath = "$($env:SystemDrive)\tiny11\sources\install.wim" & takeown "/F" $wimFilePath & icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)" try { @@ -81,7 +81,7 @@ try { # This block will catch the error and suppress it. } New-Item -ItemType Directory -Force -Path "$ScratchDisk\scratchdir" > $null -& dism /English "/mount-image" "/imagefile:$($env:SystemDrive)\tiny11\sources\install.wim" "/index:$index" "/mountdir:$($env:SystemDrive)\scratchdir" +Mount-WindowsImage -ImagePath $($env:SystemDrive)\tiny11\sources\install.wim -Index $index -ScratchDirectory $($env:SystemDrive)\scratchdir $imageIntl = & dism /English /Get-Intl "/Image:$($env:SystemDrive)\scratchdir" $languageLine = $imageIntl -split '\n' | Where-Object { $_ -match 'Default system UI language : ([a-zA-Z]{2}-[a-zA-Z]{2})' } @@ -358,13 +358,14 @@ reg unload HKLM\zSCHEMA >null reg unload HKLM\zSOFTWARE reg unload HKLM\zSYSTEM >null Write-Host "Cleaning up image..." -& 'dism' '/English' "/image:$ScratchDisk\scratchdir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase' >null +Repair-WindowsImage -ScratchDirecory $ScratchDisk\scratchdir -StartComponentCleanup -ResetBase Write-Host "Cleanup complete." Write-Host ' ' Write-Host "Unmounting image..." -& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit' +Dismount-WindowsImage -ScratchDirectory $ScratchDisk\scratchdir -Save Write-Host "Exporting image..." -& 'dism' '/English' '/Export-Image' "/SourceImageFile:$ScratchDisk\tiny11\sources\install.wim" "/SourceIndex:$index" "/DestinationImageFile:$ScratchDisk\tiny11\sources\install2.wim" '/compress:recovery' +# Compressiontype Recovery is not supported with PShell https://learn.microsoft.com/en-us/powershell/module/dism/export-windowsimage?view=windowsserver2022-ps#-compressiontype +Export-WindowsImage -SourceImagePath $ScratchDisk\tiny11\sources\install.wim -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install2.wim -CompressionType Fast Remove-Item -Path "$ScratchDisk\tiny11\sources\install.wim" -Force >null Rename-Item -Path "$ScratchDisk\tiny11\sources\install2.wim" -NewName "install.wim" >null Write-Host "Windows image completed. Continuing with boot.wim." @@ -375,7 +376,7 @@ $wimFilePath = "$($env:SystemDrive)\tiny11\sources\boot.wim" & takeown "/F" $wimFilePath >null & icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)" Set-ItemProperty -Path $wimFilePath -Name IsReadOnly -Value $false -& 'dism' '/English' '/mount-image' "/imagefile:$ScratchDisk\tiny11\sources\boot.wim" '/index:2' "/mountdir:$ScratchDisk\scratchdir" +Mount-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\boot.wim -Index 2 -ScratchDirecotry $ScratchDisk\scratchdir Write-Host "Loading registry..." reg load HKLM\zCOMPONENTS $ScratchDisk\scratchdir\Windows\System32\config\COMPONENTS reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default @@ -405,7 +406,7 @@ $regKey.Close() reg unload HKLM\zSOFTWARE reg unload HKLM\zSYSTEM >null Write-Host "Unmounting image..." -& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit' +Dismount-WindowsImage -ScratchDirectory $ScratchDisk\scratchdir -Save Clear-Host Write-Host "The tiny11 image is now completed. Proceeding with the making of the ISO..." Write-Host "Copying unattended file for bypassing MS account on OOBE..."