Skip to content

Commit dbaa1db

Browse files
authored
Merge pull request #141 from eugenesan/main
Add support for system ADK, Logging and Debug
2 parents 93eb664 + 501e10c commit dbaa1db

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

tiny11maker.ps1

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Enable debugging
2+
#Set-PSDebug -Trace 1
3+
4+
# Check if PowerShell execution is restricted
15
if ((Get-ExecutionPolicy) -eq 'Restricted') {
26
Write-Host "Your current PowerShell Execution Policy is set to Restricted, which prevents scripts from running. Do you want to change it to RemoteSigned? (yes/no)"
37
$response = Read-Host
@@ -8,26 +12,30 @@ if ((Get-ExecutionPolicy) -eq 'Restricted') {
812
exit
913
}
1014
}
15+
16+
# Check and run the script as admin if required
1117
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
1218
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
1319
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
14-
if ($myWindowsPrincipal.IsInRole($adminRole))
15-
{
16-
$Host.UI.RawUI.WindowTitle = "tiny11 builder"
17-
Clear-Host
18-
}
19-
else
20+
if (! $myWindowsPrincipal.IsInRole($adminRole))
2021
{
22+
Write-Host "Restarting Tiny11 image creator as admin in a new window, you can close this one."
2123
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
2224
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
2325
$newProcess.Verb = "runas";
2426
[System.Diagnostics.Process]::Start($newProcess);
2527
exit
2628
}
27-
Write-Host "Welcome to the tiny11 image creator! Release: 04-29-2024"
28-
Start-Sleep -Seconds 3
29+
30+
# Start the transcript and prepare the window
31+
Start-Transcript -Path "$PSScriptRoot\tiny11.log" -UseMinimalHeader
32+
33+
$Host.UI.RawUI.WindowTitle = "Tiny11 image creator"
2934
Clear-Host
35+
Write-Host "Welcome to the tiny11 image creator! Release: 04-29-2024"
36+
3037
$mainOSDrive = $env:SystemDrive
38+
$hostArchitecture = $Env:PROCESSOR_ARCHITECTURE
3139

3240
$DriveLetter = Read-Host "Please enter the drive letter for the Windows 11 image"
3341
$DriveLetter = $DriveLetter + ":"
@@ -103,7 +111,6 @@ foreach ($package in $packagesToRemove) {
103111
}
104112

105113

106-
107114
Write-Host "Removing Edge:"
108115
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\Edge" -Recurse -Force
109116
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\EdgeUpdate" -Recurse -Force
@@ -379,10 +386,24 @@ Write-Host "The tiny11 image is now completed. Proceeding with the making of the
379386
Write-Host "Copying unattended file for bypassing MS account on OOBE..."
380387
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$mainOSDrive\tiny11\autounattend.xml" -Force
381388
Write-Host "Creating ISO image..."
382-
& "$PSScriptRoot\oscdimg.exe" '-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"
389+
$ADKDepTools = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\$hostarchitecture\Oscdimg"
390+
if ([System.IO.Directory]::Exists($ADKDepTools)) {
391+
Write-Host "Will be using oscdimg.exe from system ADK."
392+
$OSCDIMG = "$ADKDepTools\oscdimg.exe"
393+
} else {
394+
Write-Host "Will be using bundled oscdimg.exe."
395+
$OSCDIMG = "$PSScriptRoot\oscdimg.exe"
396+
}
397+
& "$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"
398+
399+
# Finishing up
383400
Write-Host "Creation completed! Press any key to exit the script..."
384401
Read-Host "Press Enter to continue"
385402
Write-Host "Performing Cleanup..."
386403
Remove-Item -Path "$mainOSDrive\tiny11" -Recurse -Force
387404
Remove-Item -Path "$mainOSDrive\scratchdir" -Recurse -Force
388-
exit
405+
406+
# Stop the transcript
407+
Stop-Transcript
408+
409+
exit

0 commit comments

Comments
 (0)