GenerateAnswerFile
A command-line tool and library to generate answer files (unattend.xml or autounattend.xml) for unattended Windows installation.
Install / Use
/learn @SvenGroot/GenerateAnswerFileREADME
Windows Answer File Generator
The Answer File Generator is a command line application and library for generating answer files for unattended Windows installations. These files are commonly called unattend.xml or autounattend.xml (depending on the installation method used).
This tool can be used to generate answer files as part of an automated workflow for installing Windows, or just as a convenient way to generate answer files for personal use, without the need to install the Windows System Image Manager, or manually edit XML files.
Answer files can customize many aspects of the Windows installation, only some of which are available through this tool. Customizations supported by the Answer File Generator include:
- The installation method, partition layout, and target disk and partition.
- Enabling optional features during installation.
- Creation of local user accounts.
- Joining a domain, and adding domain accounts to a local security group.
- Configuring automatic log-on.
- The product key, computer name, language/culture, and time zone.
- Display resolution.
- Disabling Windows Defender.
- Enabling remote desktop access.
- Running PowerShell scripts and other commands on first log-on.
Answer files generated by this application will always skip the entire OOBE experience, unless no local account was created and no domain was joined.
Below, the core functionality is explained with several examples. You can also check the
full list of command line arguments, or run ./GenerateAnswerFile -Help. It's
also possible to specify customization options using a JSON file.
See what's new in Answer File Generator.
If you need additional customization, you will have to edit the generated answer file. If you'd like any other options to be available through the tool, you can file an issue or submit a pull request.
Installation method
The Answer File Generator supports several methods of installing Windows, which are specified using
the [-Install][] argument. The following values are supported.
Method | Description
----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PreInstalled | This is the default method, which is used to customize an already installed Windows image, such as one created using sysprep, or an image that was manually expanded using DISM tools such as Expand-WindowsImage. Some features are unavailable using this method, including installation of optional features.
CleanEfi | Performs a clean installation for systems using UEFI on the disk indicated by the [-InstallToDisk][] argument. This disk will be repartitioned according to the [-Partition][] argument, or using a default layout of a 100MB EFI partition, a 128MB MSR partition, and the remainder of the disk used for the OS installation.
CleanBios | Performs a clean installation for systems using legacy BIOS on the disk indicated by the [-InstallToDisk][] argument. This disk will be repartitioned according to the [-Partition][] argument, or using a default of a 100MB system partition, and the remainder of the disk used for the OS installation.
ExistingPartition | Installs Windows to an existing partition, specified using the [-InstallToDisk][] and [-InstallToPartition][] arguments. This partition will be formatted before installation, but other partitions are not touched. The system must already have a suitable system or EFI partition.
Manual | Allows the user to specify the target disk/partition during setup. When using this method, installation is not fully unattended and will require user intervention during the first stage.
The [-InstallToDisk][] argument takes the zero-based disk index, in the order that the Windows
installation (when executed manually) would list them. The [-InstallToPartition][] argument is
one-based instead (don't look at me; that's how the IDs work in the answer file).
Selecting the edition to install
Usually, Windows installation media contains multiple editions, such as Professional or Home, and
you must select which edition to install. The most common way to do this is using the product key,
which can be set using the [-ProductKey][] argument. Setting the product key will select the correct
edition to install, and activate Windows using that key. Setting a product key in the answer file is
required for most installations of Windows unless the installation method is PreInstalled.
Versions of Windows that use alternative activation methods, such as volume licensing, do not
require a product key in the answer file. In this case, if the installation media holds multiple
editions, you can select the desired one using the [-ImageIndex][] argument. You can use the
Get-WindowsImage PowerShell
command to list the images in an install.wim or install.esd file.
Passwords in answer files
Passwords are needed for several actions taken by the answer file. When creating local accounts, their initial password must be set. To join a domain, the password of a domain account with the appropriate permissions must be specified (unless a provisioned computer account is used). For automatic log-on, you must specify the password of the account that will be logged on.
[!WARNING] Passwords in answer files are not securely stored!
They are at best base64-encoded (which is easily reversible), and at worst just stored in plain text. Do not store answer files with sensitive passwords in unsecure locations, and delete such files when you are done with them.
The answer file generator also does not treat these passwords securely (it can't, to be able to write them out to the answer file in this fashion), so copies of the passwords may remain in system memory after the application is terminated.
Time zone
The Answer File Generator defaults to Pacific Standard Time. To change this, use the [-TimeZone][]
argument. Run tzutil /l for a list of accepted time zone names.
Examples
To make them easier to read, the examples below are split over multiple lines, using the PowerShell syntax to continue a command on the next line.
Clean installation using UEFI
./GenerateAnswerFile autounattend.xml `
-Install CleanEfi `
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE
The resulting answer file will install a 64 bit version of Windows on the first disk of a UEFI system, using the default UEFI partition layout, and activates it using the specified product key.
Installing a 32 bit OS
./GenerateAnswerFile autounattend.xml `
-Install CleanBios `
-ProcessorArchitecture x86 `
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE
By default, the generated answer files are for Windows editions running on 64 bit Intel or AMD
processors. Use the [-ProcessorArchitecture][] argument to specify a different CPU architecture,
such as "x86" for 32 bit processors, or "arm64" for ARM based systems.
Creating a user during installation
./GenerateAnswerFile autounattend.xml `
-Install CleanEfi `
-LocalAccount "John,Password" "Users:Steve,OtherPassword" `
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE
This example creates a user named "John" with the password "Password" (don't use that as your
password, obviously), and a user named "Steve" with the password "OtherPassword". The
[-LocalAccount][] argument takes one or more values, allowing the creation of any number of
accounts.
By default, accounts created using this method will be added to the local Administrators group. You can customize which group(s) to add them to by prefixing the account name with the group, separated by a colon. You can use multiple groups by separating them with a semicolon.
In the above example, John is an administrator, but Steve is added to the Users group, so they will be a restricted user.
Custom partition layout
If you use the CleanEfi or CleanBios installation method, you can choose to customize the
partition layout for the disk specified by [-InstallToDisk][], by using the [-Partition][]
argument. This argument accepts multiple values, each creating a partition on that disk in the order
specified.
If the [-Partition][] argument is not specified, the default partition layout for the install
method is used, as listed in the table above.
The [-Partition][] argument uses the format label:size, where label is the volume label, and
size is the size of the partition. The size can use multiple-byte units, such as GB or MB[^2], and
will be rounded down to a whole number of megabytes. If the size is *, it indicates the partition
will fill the remainder of the disk.
./GenerateAnswerFile autounattend.xml `
-Install CleanEFI `
-ProductKey ABCDE-12345-ABCDE-12345-ABCDE `
-Partition System:100MB MSR:128MB Windows:256GB Data:*
This example creates four partitions: a 100 MB EFI partition, a 128 MB Microsoft Reserved partition, a 256 GB partition that the OS will be installed to, and an additional partition that fills the remainder of the disk.
Several values for the volume label are used to create special partition types.
Label | Meaning --------------------------|--------------------------------------------------------------------------------------------------
