dism /Mount-Image /ImageFile:$BootWimPath /Index:1 /MountDir:$BootMountDir Copy-Item $UnattendPath "$BootMountDir" -Force dism /Unmount-Image /MountDir:$BootMountDir /Commit Remove-Item $BootMountDir -Recurse -Force Write-Host "[6/7] Committing changes to WIM..." -ForegroundColor Yellow dism /Unmount-Image /MountDir:$MountDir /Commit Step 7: Create new ISO Write-Host "[7/7] Creating custom ISO..." -ForegroundColor Yellow Check for oscdimg.exe (part of Windows ADK) $OscdimgPath = "$env:ProgramFiles(x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\oscdimg.exe"
@($WorkDir, $MountDir, $ExtractDir, $TempDir) | ForEach-Object if (Test-Path $ ) Remove-Item $ -Recurse -Force New-Item $_ -ItemType Directory -Force windows server 2012r2 iso
if (-not (Test-Path $OscdimgPath)) Write-Host "oscdimg.exe not found. Downloading alternative..." -ForegroundColor Yellow # Alternative: Use mkisofs from cdrtools Write-Host "Please install Windows ADK: https://go.microsoft.com/fwlink/?linkid=2165885" -ForegroundColor Red exit 1 updates # Requires: Windows ADK
$BootFile = "$ExtractDir\boot\etfsboot.com" & $OscdimgPath -bootdata:2#p0,e,b$BootFile -u2 -udfver102 $ExtractDir $OutputISOPath Write-Host "`nCleaning up temporary files..." -ForegroundColor Gray Remove-Item $WorkDir -Recurse -Force windows server 2012r2 iso
dism /Mount-Image /ImageFile:$WimPath /Index:$Index /MountDir:$MountDir if ($DriversFolder -and (Test-Path $DriversFolder)) Write-Host "[3/7] Injecting drivers..." -ForegroundColor Yellow dism /Image:$MountDir /Add-Driver /Driver:$DriversFolder /Recurse /ForceUnsigned else Write-Host "[3/7] Skipping driver injection" -ForegroundColor Gray Step 4: Add updates if ($UpdatesFolder -and (Test-Path $UpdatesFolder)) Write-Host "[4/7] Adding updates..." -ForegroundColor Yellow $Updates = Get-ChildItem $UpdatesFolder -Filter "*.msu" foreach ($Update in $Updates) Write-Host " Adding: $($Update.Name)" -ForegroundColor Gray dism /Image:$MountDir /Add-Package /PackagePath:$Update.FullName
# ====================================================== # Windows Server 2012 R2 Custom ISO Builder # Features: Unattended install, driver injection, updates # Requires: Windows ADK, oscdimg.exe, admin rights # ====================================================== param( [Parameter(Mandatory=$true)] [string]$SourceISOPath, # Original Windows Server 2012 R2 ISO