0% found this document useful (0 votes)
656 views3 pages

Sample Scripts For Autounattend - XML Files

The document provides sample PowerShell scripts for customizing Windows installations using autounattend.xml files. It includes scripts for installing software like 7-Zip and Google Chrome, configuring system settings, and managing device drivers. The scripts are designed to run in the system context before user accounts are created or when the first user logs on after installation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
656 views3 pages

Sample Scripts For Autounattend - XML Files

The document provides sample PowerShell scripts for customizing Windows installations using autounattend.xml files. It includes scripts for installing software like 7-Zip and Google Chrome, configuring system settings, and managing device drivers. The scripts are designed to run in the system context before user accounts are created or when the first user logs on after installation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/12/25, 3:13 PM Sample scripts for autounattend.

xml files

Sample scripts for [Link] files


» [Link] » [Link] generator

Custom scripts in [Link] files are a powerful mechanism to customize your Windows installation. Some sample scripts
are shown below.

Search for 7-Zip installers (like [Link] ) in the root folder of all attached drives, then install 7-Zip silently.

This is a .ps1 script that runs in the system context, before user accounts are created.

foreach( $drive in [[Link]]::GetDrives() ) {


if( $found = Join-Path -Path $[Link] -ChildPath '7z*-[Link]' -Resolve -ErrorAction 'SilentlyContinue' ) {
Start-Process -FilePath $found -ArgumentList '/S /D="C:\Program Files\7-Zip"' -Wait;
return;
}
}
'Cannot find any files that match pattern.' | Write-Warning;

Configure form

Download and install Google Chrome.

This is a .ps1 script that runs in the system context, before user accounts are created.

$uri = [uri]::new( '[Link] );


$file = "$env:TEMP\{0}" -f $[Link][-1];
[[Link]]::new().DownloadFile( $uri, $file );
Start-Process -FilePath $file -ArgumentList '/silent /install' -Wait;
Remove-Item -LiteralPath $file -ErrorAction 'SilentlyContinue';

Configure form

Use the WinGet package manager to install Firefox. This method only works with Windows 11 24H2. The script accounts for
Windows needing some time to set up WinGet properly.

This is a .ps1 script that runs when the first user logs on after Windows has been installed.

if( [[Link]]::[Link] -lt 26100 ) {


'This script requires Windows 11 24H2 or later.' | Write-Warning;
return;
}
$timeout = [datetime]::[Link]( 5 );
$exe = "$env:LOCALAPPDATA\Microsoft\WindowsApps\[Link]";

while( $true ) {
if( $exe | Test-Path ) {
& $exe install --exact --id [Link] --silent --accept-package-agreements --accept-source-agreements --source wi
return;
}
if( [datetime]::Now -gt $timeout ) {
'File {0} does not exist.' -f $exe | Write-Warning;
return;
}
Start-Sleep -Seconds 1;
}

Configure form

Install .NET Framework 3.5 from \sources\sxs\microsoft-windows-netfx3-ondemand-package~*.cab instead of


downloading it from Windows Update.

This is a .ps1 script that runs when the first user logs on after Windows has been installed.

foreach( $drive in [[Link]]::GetDrives() ) {


if( $found = Join-Path -Path $[Link] -ChildPath 'sources\sxs' -Resolve -ErrorAction 'SilentlyContinue' ) {
Enable-WindowsOptionalFeature -Online -FeatureName 'NetFx3' -Source $found -NoRestart;
return;
}
}
'Cannot find any files that match pattern.' | Write-Warning;

Configure form

Install a device driver from a .inf file. [Link] displays a dialog box (“The operation completed
successfully.”) when the driver has been installed, so the script needs to kill that process after a few seconds.

[Link] 1/3
3/12/25, 3:13 PM Sample scripts for [Link] files
This is a .ps1 script that runs in the system context, before user accounts are created.

foreach( $drive in [[Link]]::GetDrives() ) {


if( $found = Join-Path -Path $[Link] -ChildPath 'drivers\Foo*.inf' -Resolve -ErrorAction 'SilentlyContinue' )
$process = Start-Process -FilePath "$env:windir\System32\[Link]" -ArgumentList """${found}""" -PassThru;
Start-Sleep -Seconds 5;
$process | Stop-Process -ErrorAction 'SilentlyContinue';
return;
}
}
'Cannot find any files that match pattern.' | Write-Warning;

Configure form

Allow inbound ICMP messages, including echo requests (“ping”), in Windows Firewall.

This is a .ps1 script that runs in the system context, before user accounts are created.

New-NetFirewallRule -DisplayName 'ICMPv4' -Profile 'Any' -Protocol 'ICMPv4';


New-NetFirewallRule -DisplayName 'ICMPv6' -Profile 'Any' -Protocol 'ICMPv6';

Configure form

Disable AutoRun for all drives.

This is a .ps1 script that runs in the system context, before user accounts are created.

$params = @{
Path = 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer';
};
New-Item @params -ErrorAction 'SilentlyContinue';
Set-ItemProperty @params -Name 'NoDriveAutoRun' -Type 'DWord' -Value $(
( 1 -shl 26 ) - 1; # 0x3FFFFFF
);
Set-ItemProperty @params -Name 'NoDriveTypeAutoRun' -Type 'DWord' -Value $(
( 1 -shl 8 ) - 1; # 0xFF
);

Configure form

Enable and activate Ultimate Performance power plan.

This is a .ps1 script that runs in the system context, before user accounts are created.

$out = [Link] /DUPLICATESCHEME e9a42b02-d5df-448d-aa00-03f14749eb61;


if( $out -match '\s([a-f0-9-]{36})\s' ) {
[Link] /SETACTIVE $Matches[1];
}

Configure form

Set registered owner and organization of this computer. This information is shown when you run [Link] .

This is a .reg script that runs in the system context, before user accounts are created.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"RegisteredOrganization"="Foo"
"RegisteredOwner"="Bar"

Configure form

Set system-wide environment variable to configure default parameters for the internal dir command.

This is a .cmd script that runs in the system context, before user accounts are created.

[Link] DIRCMD "/A /O:GN /C /N" /m

Configure form

Disable Remote Assistence.

This is a .reg script that runs in the system context, before user accounts are created.

[Link] 2/3
3/12/25, 3:13 PM Sample scripts for [Link] files

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Remote Assistance]
"fAllowToGetHelp"=dword:00000000

Configure form

Configure non-standard directory for user profiles.

This is a .cmd script that runs in the system context, before user accounts are created.

mkdir D:\Users
[Link] add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfilesDirectory /t REG_SZ /d "D:\Users" /f
[Link] add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfilesDirectory /t REG_SZ /d "D:\U

Configure form

Change profile of Ethernet network from Public to Private.

This is a .ps1 script that runs when the first user logs on after Windows has been installed.

Get-NetConnectionProfile -InterfaceAlias 'Ethernet*' | Set-NetConnectionProfile -NetworkCategory 'Private';

Configure form

Search for a file named [Link] in the root folder of all attached drives and use it as the desktop wallpaper.

This is a .ps1 script to set the desktop wallpaper.

foreach( $drive in [[Link]]::GetDrives() ) {


if( $found = Join-Path -Path $[Link] -ChildPath '[Link]' -Resolve -ErrorAction 'SilentlyContinue' ) {
return [[Link]]::ReadAllBytes( $found );
}
}
'Cannot find any files that match pattern.' | Write-Warning;

Configure form

Contact: Christoph Schneegans (christoph@[Link])

[Link] 3/3

You might also like