Merge pull request #141 from eugenesan/main

Add support for system ADK, Logging and Debug
This commit is contained in:
NTDEV 2024-04-30 02:15:03 +03:00 committed by GitHub
commit dbaa1db7a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,7 @@
# Enable debugging
#Set-PSDebug -Trace 1
# Check if PowerShell execution is restricted
if ((Get-ExecutionPolicy) -eq 'Restricted') { if ((Get-ExecutionPolicy) -eq 'Restricted') {
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)" 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)"
$response = Read-Host $response = Read-Host
@ -8,26 +12,30 @@ if ((Get-ExecutionPolicy) -eq 'Restricted') {
exit exit
} }
} }
# Check and run the script as admin if required
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
if ($myWindowsPrincipal.IsInRole($adminRole)) if (! $myWindowsPrincipal.IsInRole($adminRole))
{
$Host.UI.RawUI.WindowTitle = "tiny11 builder"
Clear-Host
}
else
{ {
Write-Host "Restarting Tiny11 image creator as admin in a new window, you can close this one."
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = $myInvocation.MyCommand.Definition; $newProcess.Arguments = $myInvocation.MyCommand.Definition;
$newProcess.Verb = "runas"; $newProcess.Verb = "runas";
[System.Diagnostics.Process]::Start($newProcess); [System.Diagnostics.Process]::Start($newProcess);
exit exit
} }
Write-Host "Welcome to the tiny11 image creator! Release: 04-29-2024"
Start-Sleep -Seconds 3 # Start the transcript and prepare the window
Start-Transcript -Path "$PSScriptRoot\tiny11.log" -UseMinimalHeader
$Host.UI.RawUI.WindowTitle = "Tiny11 image creator"
Clear-Host Clear-Host
Write-Host "Welcome to the tiny11 image creator! Release: 04-29-2024"
$mainOSDrive = $env:SystemDrive $mainOSDrive = $env:SystemDrive
$hostArchitecture = $Env:PROCESSOR_ARCHITECTURE
$DriveLetter = Read-Host "Please enter the drive letter for the Windows 11 image" $DriveLetter = Read-Host "Please enter the drive letter for the Windows 11 image"
$DriveLetter = $DriveLetter + ":" $DriveLetter = $DriveLetter + ":"
@ -103,7 +111,6 @@ foreach ($package in $packagesToRemove) {
} }
Write-Host "Removing Edge:" Write-Host "Removing Edge:"
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\Edge" -Recurse -Force Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\Edge" -Recurse -Force
Remove-Item -Path "$mainOSDrive\scratchdir\Program Files (x86)\Microsoft\EdgeUpdate" -Recurse -Force 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
Write-Host "Copying unattended file for bypassing MS account on OOBE..." Write-Host "Copying unattended file for bypassing MS account on OOBE..."
Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$mainOSDrive\tiny11\autounattend.xml" -Force Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$mainOSDrive\tiny11\autounattend.xml" -Force
Write-Host "Creating ISO image..." Write-Host "Creating ISO image..."
& "$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" $ADKDepTools = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\$hostarchitecture\Oscdimg"
if ([System.IO.Directory]::Exists($ADKDepTools)) {
Write-Host "Will be using oscdimg.exe from system ADK."
$OSCDIMG = "$ADKDepTools\oscdimg.exe"
} else {
Write-Host "Will be using bundled oscdimg.exe."
$OSCDIMG = "$PSScriptRoot\oscdimg.exe"
}
& "$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"
# Finishing up
Write-Host "Creation completed! Press any key to exit the script..." Write-Host "Creation completed! Press any key to exit the script..."
Read-Host "Press Enter to continue" Read-Host "Press Enter to continue"
Write-Host "Performing Cleanup..." Write-Host "Performing Cleanup..."
Remove-Item -Path "$mainOSDrive\tiny11" -Recurse -Force Remove-Item -Path "$mainOSDrive\tiny11" -Recurse -Force
Remove-Item -Path "$mainOSDrive\scratchdir" -Recurse -Force Remove-Item -Path "$mainOSDrive\scratchdir" -Recurse -Force
exit
# Stop the transcript
Stop-Transcript
exit