PowerShell OSDBuilder module
Image Manager
Many system administrators use images to provide customized Windows installations that comply with company policies and requirements, so images of Windows are an important tool to help them keep their systems up to date while enforcing security. The PowerShell OSDBuilder module is designed to help manage the overhead of maintaining these images.
Online vs. Offline
Administrators are always happy to argue about which is the "better way" to manage Windows images: online or offline; however, there is no one answer to this question. If you want to maintain your Windows images online, you first need to set up a Windows installation (usually on a virtual machine) that suits your needs and then grab an image of it, either with Microsoft tools or third-party software such as Baramundi. This image then needs to be started up again for retroactive updates and refreshed after applying the updates. One argument in favor of the offline method, on the other hand, is the possibility of including updates automatically to the Windows images. One disadvantage of this method is that it is not possible to include desktop applications in a Windows image.
Neither method delivers an unequivocal knock-out factor. The IT department needs to decide which approach is the best fit for their systems. The PowerShell OSDBuilder module (Figure 1) offers one potential approach to managing images offline, which you then distribute with System Center Configuration Manager (SCCM) or some other tool. One big advantage of OSDBuilder is that all information is stored in a response file, so the file contains everything you need to update the image in question.
Installing the OSDBuilder Module
We used a newish version of Windows 10 21H1 (build 19043.1320) running on a virtual machine on VMware Workstation 16 for this example. The PowerShell commands were tested in both version 5.1, which is found by default on Windows 10, and the current version 7.2; they have only a few differences, and we will point them out at the appropriate points in the article. Installing OSDBuilder is like installing any other module in PowerShell; just type the command:
Install module -Name OSDBuilder
The module must be installed from the PowerShell Gallery (PSGallery) repository [1]. Windows classifies this repository as untrusted by default. PowerShell version 5 and version 7 both draw your attention to this fact after you enter the commands for installation, and you are prompted to decide whether you really want to do this. Installation is possible immediately after confirming in version 7, whereas you need to download and install the matching NuGet manager first in version 5. NuGet is a package manager for .NET that helps developers create, share, and use .NET libraries. After completing this step, you can then install the OSDBuilder module. To avoid problems when executing scripts, the recommendation is to lift this restriction by running the next command on the system in question:
Set-Executionpolicy Bypass -force
The -force
parameter is not absolutely necessary here, but it effectively prevents additional prompts from appearing.
Now download a current ISO file for Windows 10 21H1, version dated October 2021, from your Visual Studio account with Microsoft and double-click to mount it as drive F:
on the virtualized system. Our test system has a partition size of approximately 100GB that is mapped as drive E:
. We will be using this for OSDBuilder, which is why we need to assign the corresponding path to the module in the next step:
Get-OSDBuilder -SetPath E:\OSDBuilder
This command also specifies the target folder for the images to be created. The module now displays a mass of information on the screen. You will discover that the version of OSDBuilder you are using works with Windows 10 starting in version 1607 up to and including version 21H1 and that it supports Windows 11 version 21H2 and Windows Server starting with version 2016 1607 up to version 2022 21H1. Additionally, some shortcuts for further processing are listed, including the call
Get-OSDBuilder -CreatePaths
which creates a directory structure (Figure 2) to suit the previously specified path. Now that all the prep work is complete, it is time to select the medium to be installed.
Importing and Maintaining the Image
The DVD images for Windows officially provided by Microsoft usually contain a whole series of images with the different editions of the operating system. Because the image was already mounted as a virtual drive on the filesystem, the command
Import-OSMedia
at the PowerShell command line (Figure 3) scans the mounted DVD and lists its content; it also works if you have several disks mounted on your system.
OSDBuilder now displays the entire content of the different DVDs, and you can select the desired edition in the listing window. We used Windows 10 Pro (image index number 5) for this test.
Next, you need to import the corresponding media into the designated directories. In the process, OSDBuilder outputs information about the imported Windows image (WIM) index while creating a text logfile in the logs
directory. The next step is to update the selected Windows image:
Update-OSmedia -Download -Execute
You are then presented the selected image once again in a list, where you need to select it; the system then starts downloading the updates and integrating them into the image.
Finally, take a quick look at the tasks mentioned at the beginning. You can use these commands to initiate a build process and create media with your choice of updates:
New-OSBuildTask -TaskName <name of task> -EnableFeature <Feature to be enabled>
An example could look like:
New-OSBuildTask -TaskName "Install NetFx" -EnableFeature -EnableNetFx3
To run the build process for the selected image at the same time, change the command to:
New-OSBuild -Download -Execute -EnableNetFX -SelectUpdates
Pressing the -Download button downloads any missing updates directly from Microsoft and applies them to the image. The -Execute parameter triggers the build process directly, whereas -SelectUpdates brings up a window where you can choose from the available updates. If you run the call this way, the module prompts you for the name of the matching task. If you want this update to be "taskless," you need the command:
New-OSBuild -Download -Execute -EnableNetFX -SelectUpdates -Skiptask
After selecting the imported OS image, the module again provides a grid view with the updates from which to choose, including the service.
Buy this article as PDF
(incl. VAT)