Summary

The commands sysprep and dism can build a system image and configure what the user will see when the system it is first powered on. With customization, users can have a friendly out-of-box experience, configure his account and services, and then get a system that has been activated, updated to the latest with the driver and software installed.

OOBE:

file

This is useful for: giving PC to others, IT preparing new PCs, preparing Windows images for yourself, etc.

file

Before starting

Before starting, you need to find the sysprep binary:

C:\Windows\System32\Sysprep

file

sysprep is a CLI tool, but also has GUI.


Prepare a computer to give it to others

When you need to give a computer to a friend or prepare a computer for employees of other companies, they get the computer and should see the OOBE page and log in to their account.

However, when a PC just installed Windows, there are often not activated, no necessary drivers and software in it. Not ideal.

We can enter the audit state first.

What is the Audit state?

The Audit state can temporarily skip OOBE for activation, installing drivers and software. In the audit state, the Administrator user will be used to log in, and only computer-level operations can be performed.

After the Audit state, you must re-enter the OOBE state, so that the user who gets the computer can create a normal user on the OOBE page.

Switch to Audit state from OOBE state

If you want to enter the Audit state when you are in OOBE, you can use the command: Ctrl + Shift + F3. This will go directly to the Audit state.

Of course, when you enter the Audit state, you can use sysprep /generalize /oobe to get back to the OOBE state.

After installing the software, erase user data through the sysprep /generalize /oobe command, and the device can be handed to the user.

What's inside OOBE

The computer in the OOBE state will prompt the user to configure the language, region, keyboard layout, network, system update, license agreement, login account, privacy settings, etc. when the computer is turned on next time. The original version of Windows that has just been installed is in OOBE state.

file

Without erasing any data. But let the computer enter the OOBE state directly (not recommended):

sysprep /oobe /reboot

Erases all device data and user data, but keeps system-level settings and programs. This command is generally used to reset the computer and enter the OOBE state. This command can also be used to prepare a system disk to capture as own Windows images.

sysprep /generalize /oobe /reboot

Build your own Windows image

If you want to build a Windows image that can be directly deployed later, you can also use dism to capture the current system disk and make a wim image after generalize parameter wipes user and device data.

Once that's done, just install this image on the computer that needs to be handed over to the client, and you're done.

file

Capturing a system image can be used to quickly deploy this wim later.

It is recommended to enter the OOBE state and erase the data before capturing. That is, pass in the parameter sysprep /generalize /oobe /reboot. This ensures that the captured system image is not related to a specific device, and will not capture computer names, user information, etc. The image captured at the same time is in the OOBE state directly after deployment.

It is recommended to optimize the target image before capturing. This can speed up its startup after deployment. This step is optional.

dism /image:D:\ /optimize-image /boot

Here, I just prepared, generalized, and in the OOBE state, and did not start that Windows, it is on the D drive.

After that start capturing:

Dism /Capture-Image /ImageFile:"C:\my-image.wim" /CaptureDir:D:\ /Name:MyWindows

The captured wim file can be used to install it~


Install a wim (Windows image file) to the new device

You can replace your own wim file with install.wim in the source directory of the original Windows installation U disk. In this way, the Windows installed using this installation U disk is your own customized Windows.

Or use this command to deploy the wim file:

# (Requires admin rights, PowerShell runs)
iex ((New-Object System.Net.WebClient).DownloadString('https://github.com/Anduin2017/configuration-script-win/raw/main/Reimage.ps1'))

Based on Windows image, then customized

It's not that difficult if you've deployed a custom Windows image to your users' devices, but suddenly you want to add some extra software.

You can first enter the Audit state from the OOBE state through Ctrl + Shift + F3, and then re-enter the OOBE state after completing the relevant configuration.

Don't forget, you can always go back to OOBE state via: sysprep /oobe /reboot.

In this case, usually you don't need to run generalize, because you are not building a commonly used image, instead, you are preparing this OS for this specific machine. Just bring back to OOBE mode is enought.


Inject drivers for an existing wim image

Now open a new PowerShell session with Admin.

Run the following command to get your preferred system index.

dism /Get-ImageInfo /imagefile:"C:\install.wim"

For example, I want to install Windows 11 Pro. Then I need to remember the index: 6.

Now run the following commands to mount the system.

Remember: The index number should be your preferred OS index! I use 6 here as an example.

cd C:\
mkdir win11_temp
Dism /Mount-Image /ImageFile:C:\install.wim /MountDir:C:\win11_temp /Index:6

After mounting, don't touch those mounted files!

Inject the necessary drivers now. (You just mounted the Vultr drivers as E:\)

Run the following command:

Dism /Image:C:\win11_temp /Add-Driver /Driver:E:\ /Recurse

You may see some errors. Those are not necessary. Just ignore them. Most of the drivers are installed.

Now, commit the changes to the wim file.

Dism /Unmount-Image /MountDir:C:\win11_temp /Commit

When running the command, close all file explorer windows. Don't use your terminal to change the directory to the mounted folder! We need to make sure dism can successfully delete those mounted file or there will be an error.

After unmounting, double-check the wim file's modification time is around 2 minutes earlier from now.