Skip to content

Commit 427e6af

Browse files
authored
Merge pull request #194 from rcmaehl/patch-1
Implement #183
2 parents cd8b9a7 + fb59b44 commit 427e6af

1 file changed

Lines changed: 45 additions & 41 deletions

File tree

tiny11maker.ps1

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ if (! $myWindowsPrincipal.IsInRole($adminRole))
2929
exit
3030
}
3131

32+
param ($ScratchDisk)
33+
if ($Null -eq $ScratchDisk) {
34+
$ScratchDisk = $env:SystemDrive
35+
}
36+
3237
# Start the transcript and prepare the window
3338
Start-Transcript -Path "$PSScriptRoot\tiny11.log"
3439

3540
$Host.UI.RawUI.WindowTitle = "Tiny11 image creator"
3641
Clear-Host
3742
Write-Host "Welcome to the tiny11 image creator! Release: 05-06-24"
3843

39-
$mainOSDrive = $env:SystemDrive
4044
$hostArchitecture = $Env:PROCESSOR_ARCHITECTURE
41-
New-Item -ItemType Directory -Force -Path "$mainOSDrive\tiny11\sources" >null
45+
New-Item -ItemType Directory -Force -Path "$ScratchDisk\tiny11\sources" >null
4246
$DriveLetter = Read-Host "Please enter the drive letter for the Windows 11 image"
4347
$DriveLetter = $DriveLetter + ":"
4448

@@ -49,7 +53,7 @@ if ((Test-Path "$DriveLetter\sources\boot.wim") -eq $false -or (Test-Path "$Driv
4953
$index = Read-Host "Please enter the image index"
5054
Write-Host ' '
5155
Write-Host 'Converting install.esd to install.wim. This may take a while...'
52-
& 'DISM' /Export-Image /SourceImageFile:"$DriveLetter\sources\install.esd" /SourceIndex:$index /DestinationImageFile:"$mainOSDrive\tiny11\sources\install.wim" /Compress:max /CheckIntegrity
56+
& 'DISM' /Export-Image /SourceImageFile:"$DriveLetter\sources\install.esd" /SourceIndex:$index /DestinationImageFile:"$ScratchDisk\tiny11\sources\install.wim" /Compress:max /CheckIntegrity
5357
} else {
5458
Write-Host "Can't find Windows OS Installation files in the specified Drive Letter.."
5559
Write-Host "Please enter the correct DVD Drive Letter.."
@@ -58,14 +62,14 @@ if ((Test-Path "$DriveLetter\sources\boot.wim") -eq $false -or (Test-Path "$Driv
5862
}
5963

6064
Write-Host "Copying Windows image..."
61-
Copy-Item -Path "$DriveLetter\*" -Destination "$mainOSDrive\tiny11" -Recurse -Force > null
62-
Set-ItemProperty -Path "$mainOSDrive\tiny11\sources\install.esd" -Name IsReadOnly -Value $false > $null 2>&1
63-
Remove-Item "$mainOSDrive\tiny11\sources\install.esd" > $null 2>&1
65+
Copy-Item -Path "$DriveLetter\*" -Destination "$ScratchDisk\tiny11" -Recurse -Force > null
66+
Set-ItemProperty -Path "$ScratchDisk\tiny11\sources\install.esd" -Name IsReadOnly -Value $false > $null 2>&1
67+
Remove-Item "$ScratchDisk\tiny11\sources\install.esd" > $null 2>&1
6468
Write-Host "Copy complete!"
6569
Start-Sleep -Seconds 2
6670
Clear-Host
6771
Write-Host "Getting image information:"
68-
& 'dism' '/English' "/Get-WimInfo" "/wimfile:$mainOSDrive\tiny11\sources\install.wim"
72+
& 'dism' '/English' "/Get-WimInfo" "/wimfile:$ScratchDisk\tiny11\sources\install.wim"
6973
$index = Read-Host "Please enter the image index"
7074
Write-Host "Mounting Windows image. This may take a while."
7175
$wimFilePath = "$($env:SystemDrive)\tiny11\sources\install.wim"
@@ -76,7 +80,7 @@ try {
7680
} catch {
7781
# This block will catch the error and suppress it.
7882
}
79-
New-Item -ItemType Directory -Force -Path "$mainOSDrive\scratchdir" > $null
83+
New-Item -ItemType Directory -Force -Path "$ScratchDisk\scratchdir" > $null
8084
& dism /English "/mount-image" "/imagefile:$($env:SystemDrive)\tiny11\sources\install.wim" "/index:$index" "/mountdir:$($env:SystemDrive)\scratchdir"
8185

8286
$imageIntl = & dism /English /Get-Intl "/Image:$($env:SystemDrive)\scratchdir"
@@ -128,11 +132,11 @@ foreach ($package in $packagesToRemove) {
128132

129133

130134
Write-Host "Removing Edge:"
131-
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\Edge" -Recurse -Force >null
132-
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\EdgeUpdate" -Recurse -Force >null
133-
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\EdgeCore" -Recurse -Force >null
135+
Remove-Item -Path "$ScratchDisk\scratchdir\Program Files (x86)\Microsoft\Edge" -Recurse -Force >null
136+
Remove-Item -Path "$ScratchDisk\scratchdir\Program Files (x86)\Microsoft\EdgeUpdate" -Recurse -Force >null
137+
Remove-Item -Path "$ScratchDisk\scratchdir\Program Files (x86)\Microsoft\EdgeCore" -Recurse -Force >null
134138
if ($architecture -eq 'amd64') {
135-
$folderPath = Get-ChildItem -Path "$mainOSDrive\scratchdir\Windows\WinSxS" -Filter "amd64_microsoft-edge-webview_31bf3856ad364e35*" -Directory | Select-Object -ExpandProperty FullName
139+
$folderPath = Get-ChildItem -Path "$ScratchDisk\scratchdir\Windows\WinSxS" -Filter "amd64_microsoft-edge-webview_31bf3856ad364e35*" -Directory | Select-Object -ExpandProperty FullName
136140

137141
if ($folderPath) {
138142
& 'takeown' '/f' $folderPath '/r' >null
@@ -142,7 +146,7 @@ if ($architecture -eq 'amd64') {
142146
Write-Host "Folder not found."
143147
}
144148
} elseif ($architecture -eq 'arm64') {
145-
$folderPath = Get-ChildItem -Path "$mainOSDrive\scratchdir\Windows\WinSxS" -Filter "arm64_microsoft-edge-webview_31bf3856ad364e35*" -Directory | Select-Object -ExpandProperty FullName >null
149+
$folderPath = Get-ChildItem -Path "$ScratchDisk\scratchdir\Windows\WinSxS" -Filter "arm64_microsoft-edge-webview_31bf3856ad364e35*" -Directory | Select-Object -ExpandProperty FullName >null
146150

147151
if ($folderPath) {
148152
& 'takeown' '/f' $folderPath '/r'>null
@@ -154,22 +158,22 @@ if ($architecture -eq 'amd64') {
154158
} else {
155159
Write-Host "Unknown architecture: $architecture"
156160
}
157-
& 'takeown' '/f' "$mainOSDrive\scratchdir\Windows\System32\Microsoft-Edge-Webview" '/r' >null
158-
& 'icacls' "$mainOSDrive\scratchdir\Windows\System32\Microsoft-Edge-Webview" '/grant' "$($adminGroup.Value):(F)" '/T' '/C' >null
159-
Remove-Item -Path "$mainOSDrive\scratchdir\Windows\System32\Microsoft-Edge-Webview" -Recurse -Force >null
161+
& 'takeown' '/f' "$ScratchDisk\scratchdir\Windows\System32\Microsoft-Edge-Webview" '/r' >null
162+
& 'icacls' "$ScratchDisk\scratchdir\Windows\System32\Microsoft-Edge-Webview" '/grant' "$($adminGroup.Value):(F)" '/T' '/C' >null
163+
Remove-Item -Path "$ScratchDisk\scratchdir\Windows\System32\Microsoft-Edge-Webview" -Recurse -Force >null
160164
Write-Host "Removing OneDrive:"
161-
& 'takeown' '/f' "$mainOSDrive\scratchdir\Windows\System32\OneDriveSetup.exe" >null
162-
& 'icacls' "$mainOSDrive\scratchdir\Windows\System32\OneDriveSetup.exe" '/grant' "$($adminGroup.Value):(F)" '/T' '/C' >null
163-
Remove-Item -Path "$mainOSDrive\scratchdir\Windows\System32\OneDriveSetup.exe" -Force >null
165+
& 'takeown' '/f' "$ScratchDisk\scratchdir\Windows\System32\OneDriveSetup.exe" >null
166+
& 'icacls' "$ScratchDisk\scratchdir\Windows\System32\OneDriveSetup.exe" '/grant' "$($adminGroup.Value):(F)" '/T' '/C' >null
167+
Remove-Item -Path "$ScratchDisk\scratchdir\Windows\System32\OneDriveSetup.exe" -Force >null
164168
Write-Host "Removal complete!"
165169
Start-Sleep -Seconds 2
166170
Clear-Host
167171
Write-Host "Loading registry..."
168-
reg load HKLM\zCOMPONENTS $mainOSDrive\scratchdir\Windows\System32\config\COMPONENTS >null
169-
reg load HKLM\zDEFAULT $mainOSDrive\scratchdir\Windows\System32\config\default >null
170-
reg load HKLM\zNTUSER $mainOSDrive\scratchdir\Users\Default\ntuser.dat >null
171-
reg load HKLM\zSOFTWARE $mainOSDrive\scratchdir\Windows\System32\config\SOFTWARE >null
172-
reg load HKLM\zSYSTEM $mainOSDrive\scratchdir\Windows\System32\config\SYSTEM >null
172+
reg load HKLM\zCOMPONENTS $ScratchDisk\scratchdir\Windows\System32\config\COMPONENTS >null
173+
reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default >null
174+
reg load HKLM\zNTUSER $ScratchDisk\scratchdir\Users\Default\ntuser.dat >null
175+
reg load HKLM\zSOFTWARE $ScratchDisk\scratchdir\Windows\System32\config\SOFTWARE >null
176+
reg load HKLM\zSYSTEM $ScratchDisk\scratchdir\Windows\System32\config\SYSTEM >null
173177
Write-Host "Bypassing system requirements(on the system image):"
174178
& 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' >null
175179
& 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' >null
@@ -213,7 +217,7 @@ Write-Host "Disabling Sponsored Apps:"
213217
& 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\CloudContent' '/v' 'DisableCloudOptimizedContent' '/t' 'REG_DWORD' '/d' '1' '/f' >null
214218
Write-Host "Enabling Local Accounts on OOBE:"
215219
& 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\OOBE' '/v' 'BypassNRO' '/t' 'REG_DWORD' '/d' '1' '/f' >null
216-
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$mainOSDrive\scratchdir\Windows\System32\Sysprep\autounattend.xml" -Force >null
220+
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$ScratchDisk\scratchdir\Windows\System32\Sysprep\autounattend.xml" -Force >null
217221
Write-Host "Disabling Reserved Storage:"
218222
& 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager' '/v' 'ShippedWithReserves' '/t' 'REG_DWORD' '/d' '0' '/f' >null
219223
Write-Host "Disabling Chat icon:"
@@ -352,15 +356,15 @@ reg unload HKLM\zSCHEMA >null
352356
reg unload HKLM\zSOFTWARE
353357
reg unload HKLM\zSYSTEM >null
354358
Write-Host "Cleaning up image..."
355-
& 'dism' '/English' "/image:$mainOSDrive\scratchdir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase' >null
359+
& 'dism' '/English' "/image:$ScratchDisk\scratchdir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase' >null
356360
Write-Host "Cleanup complete."
357361
Write-Host ' '
358362
Write-Host "Unmounting image..."
359-
& 'dism' '/English' '/unmount-image' "/mountdir:$mainOSDrive\scratchdir" '/commit'
363+
& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit'
360364
Write-Host "Exporting image..."
361-
& 'dism' '/English' '/Export-Image' "/SourceImageFile:$mainOSDrive\tiny11\sources\install.wim" "/SourceIndex:$index" "/DestinationImageFile:$mainOSDrive\tiny11\sources\install2.wim" '/compress:max'
362-
Remove-Item -Path "$mainOSDrive\tiny11\sources\install.wim" -Force >null
363-
Rename-Item -Path "$mainOSDrive\tiny11\sources\install2.wim" -NewName "install.wim" >null
365+
& 'dism' '/English' '/Export-Image' "/SourceImageFile:$ScratchDisk\tiny11\sources\install.wim" "/SourceIndex:$index" "/DestinationImageFile:$ScratchDisk\tiny11\sources\install2.wim" '/compress:max'
366+
Remove-Item -Path "$ScratchDisk\tiny11\sources\install.wim" -Force >null
367+
Rename-Item -Path "$ScratchDisk\tiny11\sources\install2.wim" -NewName "install.wim" >null
364368
Write-Host "Windows image completed. Continuing with boot.wim."
365369
Start-Sleep -Seconds 2
366370
Clear-Host
@@ -369,13 +373,13 @@ $wimFilePath = "$($env:SystemDrive)\tiny11\sources\boot.wim"
369373
& takeown "/F" $wimFilePath >null
370374
& icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)"
371375
Set-ItemProperty -Path $wimFilePath -Name IsReadOnly -Value $false
372-
& 'dism' '/English' '/mount-image' "/imagefile:$mainOSDrive\tiny11\sources\boot.wim" '/index:2' "/mountdir:$mainOSDrive\scratchdir"
376+
& 'dism' '/English' '/mount-image' "/imagefile:$ScratchDisk\tiny11\sources\boot.wim" '/index:2' "/mountdir:$ScratchDisk\scratchdir"
373377
Write-Host "Loading registry..."
374-
reg load HKLM\zCOMPONENTS $mainOSDrive\scratchdir\Windows\System32\config\COMPONENTS
375-
reg load HKLM\zDEFAULT $mainOSDrive\scratchdir\Windows\System32\config\default
376-
reg load HKLM\zNTUSER $mainOSDrive\scratchdir\Users\Default\ntuser.dat
377-
reg load HKLM\zSOFTWARE $mainOSDrive\scratchdir\Windows\System32\config\SOFTWARE
378-
reg load HKLM\zSYSTEM $mainOSDrive\scratchdir\Windows\System32\config\SYSTEM
378+
reg load HKLM\zCOMPONENTS $ScratchDisk\scratchdir\Windows\System32\config\COMPONENTS
379+
reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default
380+
reg load HKLM\zNTUSER $ScratchDisk\scratchdir\Users\Default\ntuser.dat
381+
reg load HKLM\zSOFTWARE $ScratchDisk\scratchdir\Windows\System32\config\SOFTWARE
382+
reg load HKLM\zSYSTEM $ScratchDisk\scratchdir\Windows\System32\config\SYSTEM
379383
Write-Host "Bypassing system requirements(on the setup image):"
380384
& 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' >null
381385
& 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' >null
@@ -399,11 +403,11 @@ $regKey.Close()
399403
reg unload HKLM\zSOFTWARE
400404
reg unload HKLM\zSYSTEM >null
401405
Write-Host "Unmounting image..."
402-
& 'dism' '/English' '/unmount-image' "/mountdir:$mainOSDrive\scratchdir" '/commit'
406+
& 'dism' '/English' '/unmount-image' "/mountdir:$ScratchDisk\scratchdir" '/commit'
403407
Clear-Host
404408
Write-Host "The tiny11 image is now completed. Proceeding with the making of the ISO..."
405409
Write-Host "Copying unattended file for bypassing MS account on OOBE..."
406-
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$mainOSDrive\tiny11\autounattend.xml" -Force >null
410+
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$ScratchDisk\tiny11\autounattend.xml" -Force >null
407411
Write-Host "Creating ISO image..."
408412
$ADKDepTools = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\$hostarchitecture\Oscdimg"
409413
if ([System.IO.Directory]::Exists($ADKDepTools)) {
@@ -413,14 +417,14 @@ if ([System.IO.Directory]::Exists($ADKDepTools)) {
413417
Write-Host "Will be using bundled oscdimg.exe."
414418
$OSCDIMG = "$PSScriptRoot\oscdimg.exe"
415419
}
416-
& "$OSCDIMG" '-m' '-o' '-u2' '-udfver102' "-bootdata:2#p0,e,b$mainOSDrive\tiny11\boot\etfsboot.com#pEF,e,b$mainOSDrive\tiny11\efi\microsoft\boot\efisys.bin" "$mainOSDrive\tiny11" "$PSScriptRoot\tiny11.iso"
420+
& "$OSCDIMG" '-m' '-o' '-u2' '-udfver102' "-bootdata:2#p0,e,b$ScratchDisk\tiny11\boot\etfsboot.com#pEF,e,b$ScratchDisk\tiny11\efi\microsoft\boot\efisys.bin" "$ScratchDisk\tiny11" "$PSScriptRoot\tiny11.iso"
417421

418422
# Finishing up
419423
Write-Host "Creation completed! Press any key to exit the script..."
420424
Read-Host "Press Enter to continue"
421425
Write-Host "Performing Cleanup..."
422-
Remove-Item -Path "$mainOSDrive\tiny11" -Recurse -Force >null
423-
Remove-Item -Path "$mainOSDrive\scratchdir" -Recurse -Force >null
426+
Remove-Item -Path "$ScratchDisk\tiny11" -Recurse -Force >null
427+
Remove-Item -Path "$ScratchDisk\scratchdir" -Recurse -Force >null
424428

425429
# Stop the transcript
426430
Stop-Transcript

0 commit comments

Comments
 (0)