### Install VC++ Redistributable (System Script Example) Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24uri+%3D+%5Buri%5D%3A%3Anew%28+%27https%3A%2F%2Faka.ms%2Fvs%2F17%2Frelease%2Fvc_redist.x64.exe%27+%29%3B%0D%0A%24file+%3D+%22%24env%3ATEMP%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AStart-Process+-FilePath+%24file+-ArgumentList+%27%2Fquiet+%2Fnorestart%27+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&SystemScriptType0=Ps1 This PowerShell script downloads the Visual C++ Redistributable for Visual Studio 2017 (x64) to the temporary directory, installs it silently, and then removes the downloaded installer file. It's intended to be run as a system script. ```powershell $uri = [uri]::new( 'https://aka.ms/vs/17/release/vc_redist.x64.exe' ); $file = "$env:TEMP\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Start-Process -FilePath $file -ArgumentList '/quiet /norestart' -Wait; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; ``` -------------------------------- ### Command Prompt Execution Command Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24uri+%3D+%5Buri%5D%3A%3Anew%28+%27https%3A%2F%2Faka.ms%2Fvs%2F17%2Frelease%2Fvc_redist.x64.exe%27+%29%3B%0D%0A%24file+%3D+%22%24env%3ATEMP%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AStart-Process+-FilePath+%24file+-ArgumentList+%27%2Fquiet+%2Fnorestart%27+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&SystemScriptType0=Ps1 Example command to execute a .cmd script during Windows Setup. The script will be placed at C:\Windows\Setup\Scripts\unattend-01.cmd. ```cmd C:\Windows\Setup\Scripts\unattend-01.cmd ``` -------------------------------- ### Download and install Brave browser from GitHub Source: https://schneegans.de/windows/unattend-generator/samples This script runs when the first user logs on. It fetches the latest Brave browser release URL from GitHub, downloads the installer, and installs it for all users. ```powershell $user = 'brave'; $repository = 'brave-browser'; $uri = $( & { $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri "https://api.github.com/repos/${user}/${repository}/releases?per_page=100" -UseBasicParsing -Headers @{ Accept = 'application/vnd.github.v3+json'; } | Select-Object -ExpandProperty 'Content' | ConvertFrom-Json; } ) | ForEach-Object -Process { if( $_.draft -or $_.prerelease ) { return; } foreach( $b in ( $_.assets.browser_download_url -match 'StandaloneSetup\.exe$' ) ) { return [uri]::new( $b ); } } | Select-Object -First 1; if( -not $uri ) { throw 'Cannot determine URL of latest Brave installer.'; } $file = "${env:TEMP}\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Unblock-File -LiteralPath $file; Start-Process -FilePath $file -Wait; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; ``` -------------------------------- ### Install Drivers via System Script Source: https://schneegans.de/windows/unattend-generator?SystemScript0=foreach%28+%24drive+in+%5BSystem.IO.DriveInfo%5D%3A%3AGetDrives%28%29+%29+%7B%0D%0A++++if%28+%24found+%3D+Join-Path+-Path+%24drive.RootDirectory+-ChildPath+%27vioscsi%5Cw11%5Camd64%5Cvioscsi.inf%27+-Resolve+-ErrorAction+%27SilentlyContinue%27+%29+%7B%0D%0A++++++++pnputil.exe+%2Fadd-driver+%24found+%2Finstall%3B%0D%0A++++++++return%3B%0D%0A++++%7D%0D%0A%7D%0D%0A%27Cannot+find+any+files+that+match+pattern.%27+%7C+Write-Warning%3B&SystemScriptType0=Ps1 Locates and installs a specific INF driver file during the system setup phase. ```powershell foreach( $drive in [System.IO.DriveInfo]::GetDrives() ) { if( $found = Join-Path -Path $drive.RootDirectory -ChildPath 'vioscsi\w11\amd64\vioscsi.inf' -Resolve -ErrorAction 'SilentlyContinue' ) { pnputil.exe /add-driver $found /install; return; } } 'Cannot find any files that match pattern.' | Write-Warning; ``` -------------------------------- ### Download and install Google Chrome Source: https://schneegans.de/windows/unattend-generator/samples This script runs in the system context before user accounts are created. It downloads the Chrome installer to the temporary directory and installs it silently. ```powershell $uri = [uri]::new( 'https://dl.google.com/chrome/install/chrome_installer.exe' ); $file = "$env:TEMP\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Start-Process -FilePath $file -ArgumentList '/silent /install' -Wait; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; ``` -------------------------------- ### Custom Windows PE Script for Unattended Installation Source: https://schneegans.de/windows/unattend-generator?LockScreenMode=Script&LockScreenScript=foreach%28+%24drive+in+%5BSystem.IO.DriveInfo%5D%3A%3AGetDrives%28%29+%29+%7B%0D%0A++++if%28+%24found+%3D+Join-Path+-Path+%24drive.RootDirectory+-ChildPath+%27lockscreen.png%27+-Resolve+-ErrorAction+%27SilentlyContinue%27+%29+%7B%0D%0A++++++++return+%5BSystem.IO.File%5D%3A%3AReadAllBytes%28+%24found+%29%3B%0D%0A++++%7D%0D%0A%7D%0D%0A%27Cannot+find+any+files+that+match+pattern.%27+%7C+Write-Warning%3B This script handles disk partitioning, applying a Windows image, setting up boot configuration, installing drivers, stripping 8.3 filenames, disabling Windows Defender, and setting the device setup region. It includes error handling and pauses for critical operations. ```batch rem Set keyboard layout wpeutil.exe SetKeyboardLayout 0409:00000409 @for %%d in (C D E F G H I J K L M N O P Q T U V X Y Z) do @( if exist %%d:\sources\install.wim set "IMAGE_FILE=%%d:\sources\install.wim" if exist %%d:\sources\install.esd set "IMAGE_FILE=%%d:\sources\install.esd" if exist %%d:\sources\install.swm set "IMAGE_FILE=%%d:\sources\install.swm" & set "SWM_PARAM=/SWMFile:%%d:\sources\install*.swm" if exist %%d:\autounattend.xml set "XML_FILE=%%d:\autounattend.xml" if exist %%d:\$OEM$ set "OEM_FOLDER=%%d:\$OEM$" if exist %%d:\$WinPEDriver$ set "PEDRIVERS_FOLDER=%%d:\$WinPEDriver$" ) for /f "tokens=3" %%t in ('reg.exe query HKLM\System\Setup /v UnattendFile 2^>nul') do ( if exist %%t set "XML_FILE=%%t" ) @if not defined IMAGE_FILE echo Could not locate install.wim, install.esd or install.swm. & pause & exit /b 1 @if not defined XML_FILE echo Could not locate autounattend.xml. & pause & exit /b 1 rem Install drivers from $WinPEDriver$ folder if defined PEDRIVERS_FOLDER ( for /R %PEDRIVERS_FOLDER% %%f IN (*.inf) do drvload.exe "%%f" ) >X:\diskpart.txt ( echo SELECT DISK=0 echo CLEAN echo CONVERT GPT echo CREATE PARTITION EFI SIZE=300 echo FORMAT QUICK FS=FAT32 LABEL="System" echo ASSIGN LETTER=S echo CREATE PARTITION MSR SIZE=16 echo CREATE PARTITION PRIMARY echo FORMAT QUICK FS=NTFS LABEL="Windows" echo ASSIGN LETTER=W ) >X:\diskpart.txt diskpart.exe /s X:\diskpart.txt || ( echo diskpart.exe encountered an error. & pause & exit /b 1 ) set "IMG_PARAM=/Name:\"Windows 11 Pro\"" dism.exe /Apply-Image /ImageFile:%IMAGE_FILE% %SWM_PARAM% %IMG_PARAM% /ApplyDir:W:\ /CheckIntegrity /Verify || ( echo dism.exe encountered an error. & pause & exit /b 1 ) bcdboot.exe W:\Windows /s S: || ( echo bcdboot.exe encountered an error. & pause & exit /b 1 ) rem Avoid creation of recovery partition del W:\Windows\System32\Recovery\winre.wim mkdir W:\Windows\Panther copy %XML_FILE% W:\Windows\Panther\unattend.xml if defined PEDRIVERS_FOLDER ( dism.exe /Add-Driver /Image:W:\ /Driver:"%PEDRIVERS_FOLDER%" /Recurse ) rem Strip 8.3 file names fsutil.exe 8dot3name set W: 1 fsutil.exe 8dot3name strip /s /f W:\ rem Disable Windows Defender reg.exe LOAD HKLM\mount W:\Windows\System32\config\SYSTEM for %%s in (Sense WdBoot WdFilter WdNisDrv WdNisSvc WinDefend) do reg.exe ADD HKLM\mount\ControlSet001\Services\%%s /v Start /t REG_DWORD /d 4 /f reg.exe UNLOAD HKLM\mount rem Set device setup region to United States (GeoID 244) reg.exe LOAD HKLM\mount W:\Windows\System32\config\SOFTWARE reg.exe ADD "HKLM\mount\Microsoft\Windows\CurrentVersion\Control Panel\DeviceRegion" /v DeviceRegion /t REG_DWORD /d 244 /f reg.exe UNLOAD HKLM\mount rem Copy $OEM$ folder if present set "ROBOCOPY_ARGS=/E /XX /COPY:DAT /DCOPY:DAT /R:0" if defined OEM_FOLDER ( if exist "%OEM_FOLDER%\$$" robocopy.exe "%OEM_FOLDER%\$$" W:\Windows %ROBOCOPY_ARGS% if exist "%OEM_FOLDER%\$1" robocopy.exe "%OEM_FOLDER%\$1" W:\ %ROBOCOPY_ARGS% @for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @( if exist "%OEM_FOLDER%\%%d" robocopy.exe "%OEM_FOLDER%\%%d" %%d:\ %ROBOCOPY_ARGS% ) ) rem Continue with next stage of Windows Setup after reboot wpeutil.exe reboot ``` -------------------------------- ### Execute Windows Setup Scripts Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24format+%3D+%27yyyy-MM-ddTHH%5C%3Amm%5C%3AssK%27%3B%0D%0A%24now+%3D+%5Bdatetime%5D%3A%3AUtcNow%3B%0D%0A%24start+%3D+%24now.ToString%28%24format%29%3B%0D%0A%24end+%3D+%24now.AddHours%281%29.ToString%28%24format%29%3B%0D%0A%24params+%3D+%40%7B%0D%0A++++LiteralPath+%3D+%27Registry%3A%3AHKLM%5CSoftware%5CMicrosoft%5CWindowsUpdate%5CUX%5CSettings%27%3B%0D%0A++++Type+%3D+%27String%27%3B%0D%0A++++Force+%3D+%24true%3B%0D%0A++++Verbose+%3D+%24true%3B%0D%0A%7D%3B%0D%0A%27PauseFeatureUpdatesStartTime%27%2C+%27PauseQualityUpdatesStartTime%27%2C+%27PauseUpdatesStartTime%27+%7C+foreach+%7B%0D%0A++++Set-ItemProperty+%40params+-Name+%24_+-Value+%24start%3B%0D%0A%7D%3B%0D%0A%27PauseFeatureUpdatesEndTime%27%2C+%27PauseQualityUpdatesEndTime%27%2C+%27PauseUpdatesExpiryTime%27+%7C+foreach+%7B%0D%0A++++Set-ItemProperty+%40params+-Name+%24_+-Value+%24end%3B%0D%0A%7D%3B&SystemScriptType0=Ps1 Commands to run various script formats during the Windows setup process. ```cmd C:\Windows\Setup\Scripts\unattend-01.cmd ``` ```powershell powershell.exe -WindowStyle "Normal" -ExecutionPolicy "Unrestricted" -NoProfile -File "C:\Windows\Setup\Scripts\unattend-02.ps1" ``` ```reg reg.exe import "C:\Windows\Setup\Scripts\unattend-03.reg" ``` ```vbs cscript.exe //E:vbscript "C:\Windows\Setup\Scripts\unattend-04.vbs" ``` -------------------------------- ### Download and Install Software via PowerShell Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24uri+%3D+%5Buri%5D%3A%3Anew%28+%27https%3A%2F%2Fdl.google.com%2Fchrome%2Finstall%2Fchrome_installer.exe%27+%29%3B%0D%0A%24file+%3D+%22%24env%3ATEMP%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AStart-Process+-FilePath+%24file+-ArgumentList+%27%2Fsilent+%2Finstall%27+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&SystemScriptType0=Ps1 Downloads an installer executable to the temporary directory, runs it silently, and cleans up the file. ```powershell $uri = [uri]::new( 'https://dl.google.com/chrome/install/chrome_installer.exe' ); $file = "$env:TEMP\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Start-Process -FilePath $file -ArgumentList '/silent /install' -Wait; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; ``` -------------------------------- ### Install .NET Framework 3.5 from Local Source Source: https://schneegans.de/windows/unattend-generator/samples Installs the .NET Framework 3.5 using a local CAB file from the \sources\sxs\ directory. This script runs on the first user logon. ```powershell foreach( $drive in [System.IO.DriveInfo]::GetDrives() ) { if( $found = Join-Path -Path $drive.RootDirectory -ChildPath 'sources\sxs' -Resolve -ErrorAction 'SilentlyContinue' ) { Enable-WindowsOptionalFeature -Online -FeatureName 'NetFx3' -Source $found -NoRestart; return; } } 'Cannot find any files that match pattern.' | Write-Warning; ``` -------------------------------- ### Registry Import Command Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24uri+%3D+%5Buri%5D%3A%3Anew%28+%27https%3A%2F%2Faka.ms%2Fvs%2F17%2Frelease%2Fvc_redist.x64.exe%27+%29%3B%0D%0A%24file+%3D+%22%24env%3ATEMP%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AStart-Process+-FilePath+%24file+-ArgumentList+%27%2Fquiet+%2Fnorestart%27+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&SystemScriptType0=Ps1 Example command to import a .reg file during Windows Setup. This is typically used for modifying the registry. ```cmd reg.exe import "C:\Windows\Setup\Scripts\unattend-03.reg" ``` -------------------------------- ### Download and Install Brave Browser via PowerShell Source: https://schneegans.de/windows/unattend-generator?FirstLogonScript0=%24user+%3D+%27brave%27%3B%0D%0A%24repository+%3D+%27brave-browser%27%3B%0D%0A%0D%0A%24uri+%3D+%24%28%0D%0A++++%26+%7B%0D%0A++++++++%24ProgressPreference+%3D+%27SilentlyContinue%27%3B%0D%0A++++++++Invoke-WebRequest+-Uri+%22https%3A%2F%2Fapi.github.com%2Frepos%2F%24%7Buser%7D%2F%24%7Brepository%7D%2Freleases%3Fper_page%3D100%22+-UseBasicParsing+-Headers+%40%7B%0D%0A++++++++++++Accept+%3D+%27application%2Fvnd.github.v3%2Bjson%27%3B%0D%0A++++++++%7D+%7C+Select-Object+-ExpandProperty+%27Content%27+%7C+ConvertFrom-Json%3B%0D%0A++++%7D%3B%0D%0A%29+%7C+ForEach-Object+-Process+%7B%0D%0A++++if%28+%24_.draft+-or+%24_.prerelease+%29+%7B%0D%0A++++++++return%3B%0D%0A++++%7D%0D%0A++++foreach%28+%24b+in+%28+%24_.assets.browser_download_url+-match+%27StandaloneSetup%5C.exe%24%27+%29+%29+%7B%0D%0A++++++++return+%5Buri%5D%3A%3Anew%28+%24b+%29%3B%0D%0A++++%7D%0D%0A%7D+%7C+Select-Object+-First+1%3B%0D%0A++++%0D%0Aif%28+-not+%24uri+%29+%7B%0D%0A++++throw+%27Cannot+determine+URL+of+latest+Brave+installer.%27%3B%0D%0A%7D%0D%0A%0D%0A%24file+%3D+%22%24%7Benv%3ATEMP%7D%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AUnblock-File+-LiteralPath+%24file%3B%0D%0AStart-Process+-FilePath+%24file+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&FirstLogonScriptType0=Ps1 Fetches the latest Brave Browser installer from GitHub releases, downloads it to the temp directory, executes it, and cleans up. ```powershell $user = 'brave'; $repository = 'brave-browser'; $uri = $( & { $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri "https://api.github.com/repos/${user}/${repository}/releases?per_page=100" -UseBasicParsing -Headers @{ Accept = 'application/vnd.github.v3+json'; } | Select-Object -ExpandProperty 'Content' | ConvertFrom-Json; }; ) | ForEach-Object -Process { if( $_.draft -or $_.prerelease ) { return; } foreach( $b in ( $_.assets.browser_download_url -match 'StandaloneSetup\.exe$' ) ) { return [uri]::new( $b ); } } | Select-Object -First 1; if( -not $uri ) { throw 'Cannot determine URL of latest Brave installer.'; } $file = "${env:TEMP}\\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Unblock-File -LiteralPath $file; Start-Process -FilePath $file -Wait; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; ``` -------------------------------- ### PowerShell Execution Command Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24uri+%3D+%5Buri%5D%3A%3Anew%28+%27https%3A%2F%2Faka.ms%2Fvs%2F17%2Frelease%2Fvc_redist.x64.exe%27+%29%3B%0D%0A%24file+%3D+%22%24env%3ATEMP%5C%7B0%7D%22+-f+%24uri.Segments%5B-1%5D%3B%0D%0A%5BSystem.Net.WebClient%5D%3A%3Anew%28%29.DownloadFile%28+%24uri%2C+%24file+%29%3B%0D%0AStart-Process+-FilePath+%24file+-ArgumentList+%27%2Fquiet+%2Fnorestart%27+-Wait%3B%0D%0ARemove-Item+-LiteralPath+%24file+-ErrorAction+%27SilentlyContinue%27%3B&SystemScriptType0=Ps1 Example command to execute a PowerShell script during Windows Setup. It ensures unrestricted execution policy and no profile loading. ```cmd powershell.exe -WindowStyle "Normal" -ExecutionPolicy "Unrestricted" -NoProfile -File "C:\Windows\Setup\Scripts\unattend-02.ps1" ``` -------------------------------- ### Install Firefox via FirstLogon Script Source: https://schneegans.de/windows/unattend-generator?FirstLogonScript0=if%28+%5BSystem.Environment%5D%3A%3AOSVersion.Version.Build+-lt+26100+%29+%7B%0D%0A++++%27This+script+requires+Windows+11+24H2+or+later.%27+%7C+Write-Warning%3B%0D%0A++++return%3B%0D%0A%7D%0D%0A%24timeout+%3D+%5Bdatetime%5D%3A%3ANow.AddMinutes%28+5+%29%3B%0D%0A%24exe+%3D+%22%24env%3ALOCALAPPDATA%5CMicrosoft%5CWindowsApps%5Cwinget.exe%22%3B%0D%0A%0D%0Awhile%28+%24true+%29+%7B%0D%0A++++if%28+%24exe+%7C+Test-Path+%29+%7B%0D%0A++++++++%26+%24exe+install+--exact+--id+Mozilla.Firefox+--silent+--accept-package-agreements+--accept-source-agreements+--source+winget+--scope+machine%3B%0D%0A++++++++return%3B%0D%0A++++%7D%0D%0A++++if%28+%5Bdatetime%5D%3A%3ANow+-gt+%24timeout+%29+%7B%0D%0A++++++++%22File+%27%24%7Bexe%7D%27+does+not+exist.%22+%7C+Write-Warning%3B%0D%0A++++++++return%3B%0D%0A++++%7D%0D%0A++++%22Waiting+for+%27%24%7Bexe%7D%27+to+become+available...%22+%7C+Write-Host%3B%0D%0A++++Start-Sleep+-Seconds+1%3B%0D%0A%7D&FirstLogonScriptType0=Ps1 Waits for winget to become available and installs Mozilla Firefox with elevated privileges during the first user logon. ```powershell if( [System.Environment]::OSVersion.Version.Build -lt 26100 ) { 'This script requires Windows 11 24H2 or later.' | Write-Warning; return; } $timeout = [datetime]::Now.AddMinutes( 5 ); $exe = "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe"; while( $true ) { if( $exe | Test-Path ) { & $exe install --exact --id Mozilla.Firefox --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine; return; } if( [datetime]::Now -gt $timeout ) { "File '${exe}' does not exist." | Write-Warning; return; } "Waiting for '${exe}' to become available..." | Write-Host; Start-Sleep -Seconds 1; } ``` -------------------------------- ### Search and execute Ninite installer Source: https://schneegans.de/windows/unattend-generator/samples This script runs when the first user logs on. It searches for a Ninite installer in the root of all drives and executes it. ```powershell foreach( $drive in [System.IO.DriveInfo]::GetDrives() ) { if( $found = Join-Path -Path $drive.RootDirectory -ChildPath 'Ninite*Installer.exe' -Resolve -ErrorAction 'SilentlyContinue' ) { Start-Process -FilePath $found -Wait; return; } } 'Cannot find any files that match pattern.' | Write-Warning; ``` -------------------------------- ### Get Windows Image Information Source: https://schneegans.de/windows/unattend-generator?FirstLogonScript0=foreach%28+%24drive+in+%5BSystem.IO.DriveInfo%5D%3A%3AGetDrives%28%29+%29+%7B%0D%0A++++if%28+%24found+%3D+Join-Path+-Path+%24drive.RootDirectory+-ChildPath+%27sources%5Csxs%27+-Resolve+-ErrorAction+%27SilentlyContinue%27+%29+%7B%0D%0A++++++++Enable-WindowsOptionalFeature+-Online+-FeatureName+%27NetFx3%27+-Source+%24found+-NoRestart%3B%0D%0A++++++++return%3B%0D%0A++++%7D%0D%0A%7D%0D%0A%27Cannot+find+any+files+that+match+pattern.%27+%7C+Write-Warning%3B&FirstLogonScriptType0=Ps1 Use this PowerShell command to retrieve the index and name of images contained within a Windows Image (.wim) file, which is useful for selecting the correct image during unattended installations. ```powershell Get-WindowsImage -ImagePath "…\install.wim" ``` -------------------------------- ### Windows PE Custom Script Source: https://schneegans.de/windows/unattend-generator?SystemScript0=%24params+%3D+%40%7B%0D%0A++++Path+%3D+%27Registry%3A%3AHKLM%5CSoftware%5CMicrosoft%5CWindows%5CCurrentVersion%5CPolicies%5CExplorer%27%3B%0D%0A%7D%3B%0D%0ANew-Item+%40params+-ErrorAction+%27SilentlyContinue%27%3B%0D%0ASet-ItemProperty+%40params+-Name+%27NoDriveAutoRun%27+-Type+%27DWord%27+-Value+%24%28%0D%0A++++%28+1+-shl+26+%29+-+1%3B+%23+0x3FFFFFF%0D%0A%29%3B%0D%0ASet-ItemProperty+%40params+-Name+%27NoDriveTypeAutoRun%27+-Type+%27DWord%27+-Value+%24%28%0D%0A++++%28+1+-shl+8+%29+-+1%3B+%23+0xFF%0D%0A%29%3B&SystemScriptType0=Ps1 This script handles the Windows PE stage of an unattended installation. It sets the keyboard layout, locates installation media, loads drivers, partitions and formats the disk, applies the Windows image, configures boot settings, and copies necessary files. It also includes steps to disable 8.3 file names, disable Windows Defender, and set the device setup region. ```batch rem Set keyboard layout wpeutil.exe SetKeyboardLayout 0409:00000409 @for %%d in (C D E F G H I J K L M N O P Q T U V X Y Z) do @( if exist %%d:\sources\install.wim set "IMAGE_FILE=%%d:\sources\install.wim" if exist %%d:\sources\install.esd set "IMAGE_FILE=%%d:\sources\install.esd" if exist %%d:\sources\install.swm set "IMAGE_FILE=%%d:\sources\install.swm" & set "SWM_PARAM=/SWMFile:%%d:\sources\install*.swm" if exist %%d:\autounattend.xml set "XML_FILE=%%d:\autounattend.xml" if exist %%d:\$OEM$ set "OEM_FOLDER=%%d:\$OEM$" if exist %%d:\$WinPEDriver$ set "PEDRIVERS_FOLDER=%%d:\$WinPEDriver$" ) for /f "tokens=3" %%t in ('reg.exe query HKLM\System\Setup /v UnattendFile 2^>nul') do ( if exist %%t set "XML_FILE=%%t" ) @if not defined IMAGE_FILE echo Could not locate install.wim, install.esd or install.swm. & pause & exit /b 1 @if not defined XML_FILE echo Could not locate autounattend.xml. & pause & exit /b 1 rem Install drivers from $WinPEDriver$ folder if defined PEDRIVERS_FOLDER ( for /R %PEDRIVERS_FOLDER% %%f IN (*.inf) do drvload.exe "%%f" ) >X:\diskpart.txt ( echo SELECT DISK=0 echo CLEAN echo CONVERT GPT echo CREATE PARTITION EFI SIZE=300 echo FORMAT QUICK FS=FAT32 LABEL="System" echo ASSIGN LETTER=S echo CREATE PARTITION MSR SIZE=16 echo CREATE PARTITION PRIMARY echo FORMAT QUICK FS=NTFS LABEL="Windows" echo ASSIGN LETTER=W ) diskpart.exe /s X:\diskpart.txt || ( echo diskpart.exe encountered an error. & pause & exit /b 1 ) set "IMG_PARAM=/Name:\"Windows 11 Pro\"" dism.exe /Apply-Image /ImageFile:%IMAGE_FILE% %SWM_PARAM% %IMG_PARAM% /ApplyDir:W:\ /CheckIntegrity /Verify || ( echo dism.exe encountered an error. & pause & exit /b 1 ) bcdboot.exe W:\Windows /s S: || ( echo bcdboot.exe encountered an error. & pause & exit /b 1 ) rem Avoid creation of recovery partition del W:\Windows\System32\Recovery\winre.wim mkdir W:\Windows\Panther copy %XML_FILE% W:\Windows\Panther\unattend.xml if defined PEDRIVERS_FOLDER ( dism.exe /Add-Driver /Image:W:\ /Driver:"%PEDRIVERS_FOLDER%" /Recurse ) rem Strip 8.3 file names fsutil.exe 8dot3name set W: 1 fsutil.exe 8dot3name strip /s /f W:\ rem Disable Windows Defender reg.exe LOAD HKLM\mount W:\Windows\System32\config\SYSTEM for %%s in (Sense WdBoot WdFilter WdNisDrv WdNisSvc WinDefend) do reg.exe ADD HKLM\mount\ControlSet001\Services\%%s /v Start /t REG_DWORD /d 4 /f reg.exe UNLOAD HKLM\mount rem Set device setup region to United States (GeoID 244) reg.exe LOAD HKLM\mount W:\Windows\System32\config\SOFTWARE reg.exe ADD "HKLM\mount\Microsoft\Windows\CurrentVersion\Control Panel\DeviceRegion" /v DeviceRegion /t REG_DWORD /d 244 /f reg.exe UNLOAD HKLM\mount rem Copy $OEM$ folder if present set "ROBOCOPY_ARGS=/E /XX /COPY:DAT /DCOPY:DAT /R:0" if defined OEM_FOLDER ( if exist "%OEM_FOLDER%\$$" robocopy.exe "%OEM_FOLDER%\$$" W:\Windows %ROBOCOPY_ARGS% if exist "%OEM_FOLDER%\$1" robocopy.exe "%OEM_FOLDER%\$1" W:\ %ROBOCOPY_ARGS% @for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @( if exist "%OEM_FOLDER%\%%d" robocopy.exe "%OEM_FOLDER%\%%d" %%d:\ %ROBOCOPY_ARGS% ) ) rem Continue with next stage of Windows Setup after reboot wpeutil.exe reboot ``` -------------------------------- ### Windows PE Custom Script Source: https://schneegans.de/windows/unattend-generator?ComputerNameMode=Script&ComputerNameScript=Add-Type+-AssemblyName+%27Microsoft.VisualBasic%27%3B%0D%0Areturn+%5BMicrosoft.VisualBasic.Interaction%5D%3A%3AInputBox%28+%27Enter+a+valid+computer+name%3A%27%2C+%27Computer+name%27%2C+%27%27+%29%3B This script handles the Windows PE stage of an unattended installation. It sets the keyboard layout, locates installation media, loads drivers, partitions and formats disks, applies the Windows image, configures boot settings, and copies necessary files. It also includes steps to disable 8.3 file names, disable Windows Defender, and set the device setup region. ```batch rem Set keyboard layout wpeutil.exe SetKeyboardLayout 0409:00000409 @for %%d in (C D E F G H I J K L M N O P Q T U V X Y Z) do @( if exist %%d:\sources\install.wim set "IMAGE_FILE=%%d:\sources\install.wim" if exist %%d:\sources\install.esd set "IMAGE_FILE=%%d:\sources\install.esd" if exist %%d:\sources\install.swm set "IMAGE_FILE=%%d:\sources\install.swm" & set "SWM_PARAM=/SWMFile:%%d:\sources\install*.swm" if exist %%d:\autounattend.xml set "XML_FILE=%%d:\autounattend.xml" if exist %%d:\$OEM$ set "OEM_FOLDER=%%d:\$OEM$" if exist %%d:\$WinPEDriver$ set "PEDRIVERS_FOLDER=%%d:\$WinPEDriver$" ) for /f "tokens=3" %%t in ('reg.exe query HKLM\System\Setup /v UnattendFile 2^>nul') do ( if exist %%t set "XML_FILE=%%t" ) @if not defined IMAGE_FILE echo Could not locate install.wim, install.esd or install.swm. & pause & exit /b 1 @if not defined XML_FILE echo Could not locate autounattend.xml. & pause & exit /b 1 rem Install drivers from $WinPEDriver$ folder if defined PEDRIVERS_FOLDER ( for /R %PEDRIVERS_FOLDER% %%f IN (*.inf) do drvload.exe "%%f" ) >X:\diskpart.txt ( echo SELECT DISK=0 echo CLEAN echo CONVERT GPT echo CREATE PARTITION EFI SIZE=300 echo FORMAT QUICK FS=FAT32 LABEL="System" echo ASSIGN LETTER=S echo CREATE PARTITION MSR SIZE=16 echo CREATE PARTITION PRIMARY echo FORMAT QUICK FS=NTFS LABEL="Windows" echo ASSIGN LETTER=W ) diskpart.exe /s X:\diskpart.txt || ( echo diskpart.exe encountered an error. & pause & exit /b 1 ) set "IMG_PARAM=/Name:\"Windows 11 Pro\"" dism.exe /Apply-Image /ImageFile:%IMAGE_FILE% %SWM_PARAM% %IMG_PARAM% /ApplyDir:W:\ /CheckIntegrity /Verify || ( echo dism.exe encountered an error. & pause & exit /b 1 ) bcdboot.exe W:\Windows /s S: || ( echo bcdboot.exe encountered an error. & pause & exit /b 1 ) rem Avoid creation of recovery partition del W:\Windows\System32\Recovery\winre.wim mkdir W:\Windows\Panther copy %XML_FILE% W:\Windows\Panther\unattend.xml if defined PEDRIVERS_FOLDER ( dism.exe /Add-Driver /Image:W:\ /Driver:"%PEDRIVERS_FOLDER%" /Recurse ) rem Strip 8.3 file names fsutil.exe 8dot3name set W: 1 fsutil.exe 8dot3name strip /s /f W:\ rem Disable Windows Defender reg.exe LOAD HKLM\mount W:\Windows\System32\config\SYSTEM for %%s in (Sense WdBoot WdFilter WdNisDrv WdNisSvc WinDefend) do reg.exe ADD HKLM\mount\ControlSet001\Services\%%s /v Start /t REG_DWORD /d 4 /f reg.exe UNLOAD HKLM\mount rem Set device setup region to United States (GeoID 244) reg.exe LOAD HKLM\mount W:\Windows\System32\config\SOFTWARE reg.exe ADD "HKLM\mount\Microsoft\Windows\CurrentVersion\Control Panel\DeviceRegion" /v DeviceRegion /t REG_DWORD /d 244 /f reg.exe UNLOAD HKLM\mount rem Copy $OEM$ folder if present set "ROBOCOPY_ARGS=/E /XX /COPY:DAT /DCOPY:DAT /R:0" if defined OEM_FOLDER ( if exist "%OEM_FOLDER%\$$" robocopy.exe "%OEM_FOLDER%\$$" W:\Windows %ROBOCOPY_ARGS% if exist "%OEM_FOLDER%\$1" robocopy.exe "%OEM_FOLDER%\$1" W:\ %ROBOCOPY_ARGS% @for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @( if exist "%OEM_FOLDER%\%%d" robocopy.exe "%OEM_FOLDER%\%%d" %%d:\ %ROBOCOPY_ARGS% ) ) rem Continue with next stage of Windows Setup after reboot wpeutil.exe reboot ``` -------------------------------- ### Install MSIX Bundle from GitHub Release Source: https://schneegans.de/windows/unattend-generator/samples Downloads and installs the latest MSIX bundle from a GitHub repository's releases. This script runs after the initial Windows installation. ```powershell Invoke-WebRequest -Uri "https://api.github.com/repos/${user}/${repository}/releases" -UseBasicParsing -Headers @{ Accept = 'application/vnd.github.v3+json'; } | Select-Object -ExpandProperty 'Content' | ConvertFrom-Json; }; ) | Where-Object -FilterScript { -not $_.draft -and -not $_.prerelease; } | Select-Object -First 1; $latest.assets.browser_download_url | Where-Object -FilterScript { $_ -match '\.msixbundle$'; } | Select-Object -First 1 | ForEach-Object -Process { $uri = [uri]::new( $_ ); $file = "$env:TEMP\{0}" -f $uri.Segments[-1]; [System.Net.WebClient]::new().DownloadFile( $uri, $file ); Add-AppxProvisionedPackage -Online -PackagePath $file -SkipLicense; Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue'; }; ```