Created
February 2, 2024 00:32
-
-
Save atahabaki/0ccd86f413a92ea9f6ea690a66834c16 to your computer and use it in GitHub Desktop.
Breeze 11: Windows 11 ISO Modification via Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check 7-Zip installed | |
Write-Information "Checking 7-Zip installed or not..." | |
function GetLocation-WithPrompt() { | |
[OutputType([string])] | |
param( | |
[ValidateNotNullOrEmpty()] | |
[string] $Name = "7-Zip" | |
) | |
$location = Read-Host -Prompt "Enter valid $Name file location" | |
if ( -Not (Test-Path $location)) { | |
Write-Error "$Name not found. Install it and run this script again." | |
exit -1 | |
} else { | |
return $location | |
} | |
} | |
function GetRequirement-Location() { | |
[OutputType([string])] | |
param ( | |
[ValidateNotNullOrEmpty()] | |
[string] $Name = "7-Zip", | |
[ValidateNotNullOrEmpty()] | |
[bool] $IgnoreLocations, | |
[ValidateNotNullOrEmpty()] | |
[string[]] $Locations = @("$env:PROGRAMFILES/7-Zip/7z.exe", "${env:PROGRAMFILES(X86)}\7-Zip\7z.exe") | |
) | |
if (-Not ($IgnoreLocations)) { | |
$not_found_count = 0; | |
foreach ($location in $Locations) { | |
if (-Not (Test-Path $location)) { | |
$not_found_count += 1 | |
Write-Warning "$Name is not found at $location." | |
} else { | |
return $location | |
} | |
} | |
if ($not_found_count -eq $Locations.Length) { | |
return (GetLocation-WithPrompt -Name $Name) | |
} | |
} else { | |
return (GetLocation-WithPrompt -Name $Name) | |
} | |
} | |
$EXTRACTOR = GetRequirement-Location -Name "7-Zip" -Locations @("$env:PROGRAMFILES\7-Zip\7z.exe", "${env:PROGRAMFILES(X86)}\7-Zip\7z.exe") | |
$ROOTDIR = "C:\Breeze11" | |
New-Item -ItemType Directory $ROOTDIR -Force | Out-Null | |
Set-Location $ROOTDIR | |
@(".\ISO", ".\MOUNT", ".\UPDATES", ".\DRIVERS", ".\BUILD") | foreach { New-Item -ItemType Directory -Path $_ -Force | Out-Null } | |
### Get ISO location | |
function GetISO-Location() { | |
$ISO_LOCATION = Read-Host -Prompt "Enter Windows ISO location" | |
if ( -Not (Test-Path $ISO_LOCATION)) { | |
Write-Warning "ISO is not found." | |
GetISO-Location | |
} else { | |
return $ISO_LOCATION | |
} | |
} | |
$ISO_LOCATION = GetISO-Location | |
### Extract | |
Write-Information "Extracting Windows ISO to $ROOTDIR\ISO..." | |
Start-Process -FilePath $EXTRACTOR -ArgumentList "x -o`"$ROOTDIR\ISO\`" $ISO_LOCATION" -Wait -RedirectStandardError "extract_error.log" | |
$WIMLOC = "$ROOTDIR\ISO\sources\install.wim" | |
### Select Windows Edition | |
Get-WindowsImage -ImagePath $WIMLOC | Format-Table -Property ImageIndex, ImageName | |
$EDITION = Read-Host -Prompt "Enter Windows Edition Number" | |
### Mount Windows Image | |
Mount-WindowsImage -ImagePath $WIMLOC -Index "$EDITION" -Path "$ROOTDIR\MOUNT" -CheckIntegrity -Optimize | |
### Infinite PromptInPlace | |
function Infinite-PromptInPlace() { | |
param( | |
[ValidateNotNullOrEmpty()] | |
[string] $Name = "Updates" | |
) | |
$choice = $Host.UI.PromptForChoice("Placement of $Name", "Everything is in place?", @("Yes", "No"), 1) | |
if ($choice -eq 1) { Infinite-Prompt -Name $Name } | |
} | |
### Install Updates | |
$choice = $Host.UI.PromptForChoice("Embedding Updates", "Do you want to embed Windows Update Packages?", @("Yes","No"), 1) | |
if ($choice -ne 1) { | |
Write-Host "Place updates to the `"$ROOTDIR\UPDATES`"" | |
explorer "$ROOTDIR\UPDATES" | |
Infinite-PromptInPlace | |
Get-ChildItem -Path "$ROOTDIR\UPDATES" -Filter *.msu | foreach { | |
Write-Host "Installing Update `"${$_.FullName}`"" | |
Add-WindowsPackage -PackagePath $_.FullName -Path "$ROOTDIR\MOUNT" -NoRestart | |
} | |
} | |
### Install Drivers | |
$choices = @("Export and install drivers from the current installation", "Provide drivers in the designated folder", "Skip driver installation") | |
$choice = $Host.UI.PromptForChoice("Drivers Installation", "Which of the following options you want?", $choices, 1) | |
if ($choice -ne 2) { | |
if ($choice -eq 0) { | |
Export-WindowsDriver -Online -Destination "$ROOTDIR\DRIVERS" | |
} | |
if ($choice -eq 1) { | |
Write-Host "Place the drivers to `"$ROOTDIR\DRIVERS`" folder" | |
explorer "$ROOTDIR\DRIVERS" | |
Infinite-PromptInPlace -Name "Drivers" | |
} | |
Add-WindowsDriver -Recurse -Path "$ROOTDIR\MOUNT" -Driver "$ROOTDIR\DRIVERS" | |
} | |
Dismount-WindowsImage -Save -Path "$ROOTDIR\MOUNT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment