It’s something that I hadn’t tried in a while: Capturing a custom Windows 11 image using MDT. But there were a few posts on Reddit commenting about challenges doing so, so I thought I’d try it. First off, you should make sure that you have MDT fully updated; Johan’s guide is a good start:

The main points from that:

A few general tips that I would add:

  • Use a Hyper-V UEFI (Gen 2) VM for doing this so you can avoid the need for injecting extra drivers, and allocate a full 4GB to the VM without using dynamic memory (since Windows PE can struggle to initialize with small amounts of initial RAM).
  • Don’t enable BitLocker or any other encryption mechanism when building and capturing an image (unless you like frustration).
  • Expect the image to get bigger. Even if you change nothing (no apps, no updates, etc.), it’s likely that the resulting WIM file will grow by at least a gigabyte over the source WIM that you started with. If you’re going through this exercise just to get the latest patches installed, grab the latest monthly ISO from https://my.visualstudio.com (requires a subscription) because it’s faster and easier, and Microsoft goes through more effort to get the image as small as possible (which is still quite large, over 4GB).
  • Don’t modify the unattend.xml to use CopyProfile. Microsoft doesn’t do much (if anything) to test it, so over time it seems to cause more and more issues — find another way to customize the user profile, ideally when you deploy the image, not before you capture it.

OK, so what else can go wrong? Two common issues:

  • New UWP/MSIX apps or app updates are installed. Sysprep will fail if there are any apps installed that aren’t also provisioned in the OS; the root problem is described at https://learn.microsoft.com/en-us/troubleshoot/windows-client/setup-upgrade-and-drivers/sysprep-fails-remove-or-update-store-apps. That can happen from store updates (if the machine is able to access the internet and is online long enough to detect updated apps) or from Windows updates that add apps, e.g. the Copilot app that Johan’s blog points out.
  • Pending file deletions. I’ve seen this happen more than once in my own VMs: something (an update, an app, Windows itself, hard to say) tries to delete an in-use file and can’t, so it creates a registry entry to cause the file to be deleted on the next reboot. The LTISysprep.wsf script detects this and automatically reboots the computer, which should take care of that. But there’s a bug in the LTISysprep.wsf script that causes the staging of Windows PE to fail after that reboot because the system (boot) volume no longer has a drive letter attached and the script doesn’t re-add that drive letter.

Johan’s post addresses the first item if the only updated or new app is the Copilot app (which will happen if you use 24H2 media updated in November or later), but if you are unlucky (something that gets more and more likely the longer your task sequence runs, assuming your device has internet access to communicate with the store) you could run into more apps that cause the same problem. You can check the C:\Windows\system32\sysprep\panther\Setupact.log to see what app is causing the problem, then add it to the PowerShell script that Johan specified. (I have cheated in the past and just removed all apps from the built-in Administrator account using “Get-AppxPackage | Remove-AppxPackage”, but that’s probably not the greatest idea overall. And it’s surprisingly hard to write a PowerShell script that says “check all installed apps to see if they are newer than the provisioned apps.”)

So how do you address the second issue above with pending deletions? Notice that Johan’s example task sequence has a “Restart computer” step after the script that removes the Copilot app:

In most cases, that should also take care of processing those deletions.

So here’s what my edited task sequence looks like:

I didn’t add the “Suspend” step because I didn’t need to do anything manually. (If you are thinking about manually setting up the OS and then running a “Sysprep and Capture” task sequence, I wouldn’t recommend it — that encourages bad habits. Minimize or eliminate the manual tasks, and use the LTISuspend.wsf script to pause the task sequence so you can do any required tasks. And I’d typically suggest having the app removal and reboot steps after the suspend step, just in case your manual activities either cause an issue or cause a delay that lets other things get updated.)

And the final result (with those warnings coming from Windows PE trying to connect to the deployment share before the network was ready, not a fatal issue since it retried and succeeded):


Discover more from Out of Office Hours

Subscribe to get the latest posts sent to your email.

Trending