152 lines
6.1 KiB
PowerShell
152 lines
6.1 KiB
PowerShell
#
|
||
# Treiber in ein Windows
|
||
#
|
||
|
||
# Diese Variablen jeweils anpassen:
|
||
# Installationspfad
|
||
$droot = "F:\isobuilder"
|
||
# Name und Ort der Qeull-ISO Datei
|
||
$isoFile = "F:\public\Win11_24H2_German_x64.iso"
|
||
# Name und Ort der neu zu erstellenden .ISO
|
||
$isoOutfile = "F:\public\Win11_24H2_AE-Edition_x64.iso"
|
||
|
||
# -------------------------------------------------------------------------------
|
||
# Ab hier nichts mehr ändern, außer Du weisst was Du tust!
|
||
# -------------------------------------------------------------------------------
|
||
$workPath = "${droot}\mount\work"
|
||
$toolPath = "${droot}\tools"
|
||
$isoPath = "${droot}\mount\ISO"
|
||
$addFiles = "${droot}\addfiles"
|
||
$wimPath = "${addFiles}\Sources"
|
||
|
||
$wimInstallIndex = 5
|
||
|
||
function CreateDirs {
|
||
New-Item -ItemType Directory -Force -Path "${isoPath}" > $null
|
||
New-Item -ItemType Directory -Force -Path "${workPath}" > $null
|
||
New-Item -ItemType Directory -Force -Path "${addfiles}" > $null
|
||
New-Item -ItemType Directory -Force -Path "${addfiles}\Updates" > $null
|
||
New-Item -ItemType Directory -Force -Path "${addfiles}\Sources" > $null
|
||
New-Item -ItemType Directory -Force -Path "${wimpath}" > $null
|
||
New-Item -ItemType Directory -Force -Path "${droot}\mount\boot" > $null
|
||
New-Item -ItemType Directory -Force -Path "${droot}\mount\install" > $null
|
||
New-Item -ItemType Directory -Force -Path "${droot}\drivers\boot" > $null
|
||
New-Item -ItemType Directory -Force -Path "${droot}\drivers\install" > $null
|
||
}
|
||
function DiscardMounts {
|
||
Write-Host "Lösche eventuelle Mounts"
|
||
DISM /Unmount-Wim /MountDir:${droot}\mount\boot /Discard
|
||
DISM /Unmount-Wim /MountDir:${droot}\mount\install /Discard
|
||
}
|
||
function CopyIso {
|
||
Write-Host "Es wird die Datei ${isoFile} als Vorlage verwendet!"
|
||
# mountet eine Windows .ISO Datei und merkt sich den Laufwerksbuchstaben -----------------------------
|
||
$mountResult = Mount-DiskImage -ImagePath $isoFile -PassThru
|
||
$driveLetter = ($mountResult | Get-Volume).DriveLetter
|
||
Write-Host "Mounte .ISO Datei nach ${driveLetter}: ..."
|
||
|
||
# Kopiert die ISO auf das lokale Laufwerk ------------------------------------------------------------
|
||
Write-Host "Kopiere Inhalt der .ISO ..."
|
||
New-Item -ItemType Directory -Force -Path "$isoPath" > $null
|
||
Copy-Item -Path "${driveLetter}:\*" -Destination "$isoPath" -Recurse -Force
|
||
|
||
if(-not(Test-Path "${wimPath}\boot.wim"))
|
||
{
|
||
Write-Host "Kopiere boot.wim ..."
|
||
cp ${driveLetter}:\sources\boot.wim ${wimPath}
|
||
attrib -R ${wimPath}\boot.wim
|
||
} else {
|
||
Write-Host "boot.wim ist bereits vorhanden und wird <20>bersprungen."
|
||
}
|
||
if(-not(Test-Path "${wimPath}\install.wim"))
|
||
{
|
||
Write-Host "Kopiere install.wim..."
|
||
cp ${driveLetter}:\sources\install.wim ${wimPath}
|
||
attrib -R ${wimPath}\install.wim
|
||
} else {
|
||
Write-Host "install.wim ist bereits vorhanden und wird <20>bersprungen."
|
||
}
|
||
|
||
Write-Host "Kopieren abgeschlossen."
|
||
|
||
# Trenne .ISO Datei ----------------------------------------------------------------------------------
|
||
Write-Host "Trenne .ISO Datei..."
|
||
Dismount-DiskImage -ImagePath $isoFile
|
||
}
|
||
function ConvertEsd {
|
||
# Achtung! Funktion ist unfertig!
|
||
Write-Host "Konvertiere install.esd nach install.wim..."
|
||
dism /get-wiminfo /wimfile:${droot}\install.esd
|
||
dism /export-image /SourceImageFile:${droot}\install.esd /SourceIndex:5 /DestinationImageFile:${droot}\install.wim /Compress:max /CheckIntegrity
|
||
attrib -R ${droot}\install.wim
|
||
}
|
||
function ModifyBoot {
|
||
# f<>ge Treiber in das boot.wim Image ein
|
||
Write-Host "Mounte die boot.wim..."
|
||
Write-Host "F<EFBFBD>ge die Treiber unterhalb von drivers\boot in die boot.wim ein..."
|
||
#dism /get-wiminfo /wimfile:${wimPath}\boot.wim
|
||
DISM /Mount-Wim /WimFile:${wimPath}\boot.wim /Index:2 /MountDir:${droot}\mount\boot
|
||
DISM /Image:${droot}\mount\boot /Add-Driver /Driver:${droot}\drivers\boot /recurse /forceunsigned
|
||
Write-Host "Trenne boot.wim..."
|
||
DISM /Unmount-Wim /MountDir:${droot}\mount\boot /Commit
|
||
}
|
||
function ModifyInstall {
|
||
# F<>ge Treiber und Updates in das install.wim Image ein
|
||
#Write-Host "Extrahiere Index: ${wimINstallIndex} nach install.wim..."
|
||
# Zeige die Enthaltenen Windows Editionen
|
||
#dism /get-wiminfo /wimfile:${addFiles}\Sources\install.wim
|
||
# Extrahiere Edition Windows 11 Pro (Index: 5)
|
||
# DISM /Export-Image /SourceImageFile:"${isoPath}\Sources\install.wim" /SourceIndex:${wimInstallIndex} /DestinationImageFile:"${addFiles}\Sources\install.wim"
|
||
Write-Host "Mounte die install.wim..."
|
||
Write-Host " F<>ge die Treiber unterhalb von drivers\install in die install.wim ein..."
|
||
# Mounte Extrahiertes Image
|
||
DISM /Mount-Wim /WimFile:${addFiles}\Sources\install.wim /Index:${wimInstallIndex} /MountDir:${droot}\mount\install
|
||
# Arbeite Treiber & Updates ein
|
||
DISM /Image:${droot}\mount\install /Add-Driver /Driver:${droot}\drivers\install /recurse /forceunsigned
|
||
DISM /Image:${droot}\mount\install /add-package /PackagePath:${droot}\addfiles\updates
|
||
Write-Host "Trenne install.wim..."
|
||
DISM /Unmount-Wim /MountDir:${droot}\mount\install /Commit
|
||
}
|
||
function CreateISO {
|
||
Write-Host "Erstelle neues Windows-Image ..."
|
||
|
||
Write-Host " l<>sche Work-Verzeichnis ..."
|
||
Remove-Item -Path "${workPath}\*" -Force -Recurse
|
||
|
||
Write-Host " kopiere originale ISO Dateien ..."
|
||
cp ${isoPath}\* ${workPath} -Recurse -Force
|
||
|
||
Write-Host " kopiere zus<75>zliche Dateien ..."
|
||
cp ${addFiles}\* ${workPath} -Recurse -Force
|
||
|
||
Write-Host "Erstelle ${isoOutfile} ..."
|
||
# use bootfile provided by oscdimg
|
||
Start-Process -Filepath "$toolPath\oscdimg.exe" -ArgumentList "-b`"${toolPath}\efisys.bin`" -udfver102 -u2 -h -m -o ${workPath} ${isoOutfile}" -Wait -WindowStyle Minimized
|
||
# use bootfile from ISO
|
||
Start-Process -Filepath "$toolPath\oscdimg.exe" -ArgumentList "-b`"${isoPath}\efi\microsoft\boot\efisys.bin`" -udfver102 -u2 -h -m -o ${workPath} ${isoOutfile}" -Wait -WindowStyle Minimized
|
||
}
|
||
function CleanUp {
|
||
Write-Host "R<EFBFBD>ume auf..."
|
||
# HKLM\SOFTWARE\Microsoft\WIMMount\mounted images\
|
||
DISM /Cleanup-Wim
|
||
DISM /Get-MountedImageInfo
|
||
DISM /Get-MountedWimInfo
|
||
}
|
||
function CleanBuild {
|
||
Write-Host "R<EFBFBD>ume auf..."
|
||
Remove-Item -Path "${workPath}\*" -Force -Recurse
|
||
Remove-Item -Path "${isoPath}\*" -Force -Recurse
|
||
Remove-Item -Path "${wimPath}\*.wim" -Force
|
||
}
|
||
|
||
function RunAll {
|
||
CreateDirs
|
||
DiscardMounts
|
||
CopyIso
|
||
ModifyBoot
|
||
ModifyInstall
|
||
CleanUp
|
||
CreateISO
|
||
}
|
||
|