Skip to content

Commit bba078c

Browse files
authored
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.
1 parent 233b6b0 commit bba078c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tiny11maker.ps1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ $DriveLetter = $DriveLetter + ":"
4949
if ((Test-Path "$DriveLetter\sources\boot.wim") -eq $false -or (Test-Path "$DriveLetter\sources\install.wim") -eq $false) {
5050
if ((Test-Path "$DriveLetter\sources\install.esd") -eq $true) {
5151
Write-Host "Found install.esd, converting to install.wim..."
52-
& 'dism' '/English' "/Get-WimInfo" "/wimfile:$DriveLetter\sources\install.esd"
52+
Get-WindowsImage -ImagePath $DriveLetter\sources\install.esd
5353
$index = Read-Host "Please enter the image index"
5454
Write-Host ' '
5555
Write-Host 'Converting install.esd to install.wim. This may take a while...'
56-
& 'DISM' /Export-Image /SourceImageFile:"$DriveLetter\sources\install.esd" /SourceIndex:$index /DestinationImageFile:"$ScratchDisk\tiny11\sources\install.wim" /Compress:max /CheckIntegrity
57-
} else {
56+
Export-WindowsImage -SourceImagePath $DriveLetter\sources\install.esd -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install.wim -Compressiontype Maximum -CheckIntegrity
57+
} else {
5858
Write-Host "Can't find Windows OS Installation files in the specified Drive Letter.."
5959
Write-Host "Please enter the correct DVD Drive Letter.."
6060
exit
@@ -69,10 +69,10 @@ Write-Host "Copy complete!"
6969
Start-Sleep -Seconds 2
7070
Clear-Host
7171
Write-Host "Getting image information:"
72-
& 'dism' '/English' "/Get-WimInfo" "/wimfile:$ScratchDisk\tiny11\sources\install.wim"
72+
Get-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\install.wim
7373
$index = Read-Host "Please enter the image index"
7474
Write-Host "Mounting Windows image. This may take a while."
75-
$wimFilePath = "$($env:SystemDrive)\tiny11\sources\install.wim"
75+
$wimFilePath = "$($env:SystemDrive)\tiny11\sources\install.wim"
7676
& takeown "/F" $wimFilePath
7777
& icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)"
7878
try {
@@ -81,7 +81,7 @@ try {
8181
# This block will catch the error and suppress it.
8282
}
8383
New-Item -ItemType Directory -Force -Path "$ScratchDisk\scratchdir" > $null
84-
& dism /English "/mount-image" "/imagefile:$($env:SystemDrive)\tiny11\sources\install.wim" "/index:$index" "/mountdir:$($env:SystemDrive)\scratchdir"
84+
Mount-WindowsImage -ImagePath $($env:SystemDrive)\tiny11\sources\install.wim -Index $index -ScratchDirectory $($env:SystemDrive)\scratchdir
8585

8686
$imageIntl = & dism /English /Get-Intl "/Image:$($env:SystemDrive)\scratchdir"
8787
$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
358358
reg unload HKLM\zSOFTWARE
359359
reg unload HKLM\zSYSTEM >null
360360
Write-Host "Cleaning up image..."
361-
& 'dism' '/English' "/image:$ScratchDisk\scratchdir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase' >null
361+
Repair-WindowsImage -ScratchDirecory $ScratchDisk\scratchdir -StartComponentCleanup -ResetBase
362362
Write-Host "Cleanup complete."
363363
Write-Host ' '
364364
Write-Host "Unmounting image..."
365-
& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit'
365+
Dismount-WindowsImage -ScratchDirectory $ScratchDisk\scratchdir -Save
366366
Write-Host "Exporting image..."
367-
& 'dism' '/English' '/Export-Image' "/SourceImageFile:$ScratchDisk\tiny11\sources\install.wim" "/SourceIndex:$index" "/DestinationImageFile:$ScratchDisk\tiny11\sources\install2.wim" '/compress:recovery'
367+
# Compressiontype Recovery is not supported with PShell https://learn.microsoft.com/en-us/powershell/module/dism/export-windowsimage?view=windowsserver2022-ps#-compressiontype
368+
Export-WindowsImage -SourceImagePath $ScratchDisk\tiny11\sources\install.wim -SourceIndex $index -DestinationImagePath $ScratchDisk\tiny11\sources\install2.wim -CompressionType Fast
368369
Remove-Item -Path "$ScratchDisk\tiny11\sources\install.wim" -Force >null
369370
Rename-Item -Path "$ScratchDisk\tiny11\sources\install2.wim" -NewName "install.wim" >null
370371
Write-Host "Windows image completed. Continuing with boot.wim."
@@ -375,7 +376,7 @@ $wimFilePath = "$($env:SystemDrive)\tiny11\sources\boot.wim"
375376
& takeown "/F" $wimFilePath >null
376377
& icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)"
377378
Set-ItemProperty -Path $wimFilePath -Name IsReadOnly -Value $false
378-
& 'dism' '/English' '/mount-image' "/imagefile:$ScratchDisk\tiny11\sources\boot.wim" '/index:2' "/mountdir:$ScratchDisk\scratchdir"
379+
Mount-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\boot.wim -Index 2 -ScratchDirecotry $ScratchDisk\scratchdir
379380
Write-Host "Loading registry..."
380381
reg load HKLM\zCOMPONENTS $ScratchDisk\scratchdir\Windows\System32\config\COMPONENTS
381382
reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default
@@ -405,7 +406,7 @@ $regKey.Close()
405406
reg unload HKLM\zSOFTWARE
406407
reg unload HKLM\zSYSTEM >null
407408
Write-Host "Unmounting image..."
408-
& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit'
409+
Dismount-WindowsImage -ScratchDirectory $ScratchDisk\scratchdir -Save
409410
Clear-Host
410411
Write-Host "The tiny11 image is now completed. Proceeding with the making of the ISO..."
411412
Write-Host "Copying unattended file for bypassing MS account on OOBE..."

0 commit comments

Comments
 (0)