Recursively adding drivers in a distribution share to a WinPE image with “FOR” and “peimg”

Microsoft has provided a handy tool for adding additional drivers into Windows Vista and WinPE 2.0 WIM files.  This tool is called “PEIMG”, and it is included in the Windows AIK, available from  Unfortunately, PEIMG does not have a recursive function, so if you want to add all of the drivers in a complex driver store (e.g. all of the drivers in a BDD Distribution Share), you need to do some scripting.

Fortunately, not much scripting is required… FOR comes to the rescue again!

for /R . %i in (*.inf) do peimg /inf=”%i” e:winpe_x86mountWindows

In this case, we are using “/R” to tell “FOR” that we want it to recurse though the given directory path (in this example, “.”) setting the variable “%i” to be equal to each “inf” file that it finds.  On each pass we run “peimg /inf=”, injecting our variable as the inf file to inject.

All of this assumes that you have already mounted the target WIM file into the directory e:winpe_x86mountWindows.

We could fairly easily automate the whole winpe build process by stringing together these commands:

  1. imagex /mountrw <WIM file> <WIM Index> <mount directory>
  2. for /R .net %i in (*.inf) do peimg /inf=”%i” <mountDirectory>windows
  3. for /R .hdc %i in (*.inf) do peimg /inf=”%i” <mountDirectory>windows
  4. for /R .system %i in (*.inf) do peimg /inf=”%i” <mountDirectory>windows
  5. for /R .SCSIAdapter %i in (*.inf) do peimg /inf=”%i” <mountDirectory>windows
  6. imagex /unmount /commit <mountDirectory>

We could then use WDSUtil to import the image into a Windows DS server, convert it to a “discover” image.  OSCDIMG from the Windows AIK to create automatically a WDS Discover ISO file.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s