Use DeployImage Module and PowerShell to Build a Nano Server: Part 2


Summary: Sean Kearney uses the New-NanoServerWim cmdlet from the DeployImage module to build an updated Nano Server WIM file.

Honorary Scripting Guy, Sean Kearney, is here today continuing forward with creating a new Nano Server with the DeployImage module.

   Note   This is a five-part series that includes the following posts:

I’m presuming that you have the media for the Nano Server ready, and it is sitting off the NanoServer folder at the root of the Windows Server 2016 TP4 media.

To customize the Nano Server WIM file, we use the same process as customizing any other WIM file (which is nice—nothing new to learn):

  • Copy the WIM file somewhere so you can have Read/Write access to it
  • Mount the WIM file to allow you to update it
  • Add drivers to the offline image as needed
  • Add packages to the offline image as needed
  • Drop in file and registry customizations (such an Unattend.xml file)
  • Dismount the image and save the changes

I’m going to presume that the Windows Server 2016 media is on drive X, and I’d like to copy the NanoServer folder to drive C. I am actually going to copy the entire folder structure. I’ll need this later when I’m building out a USB key to deploy the Nano Server. I can do this in one line in PowerShell:

Copy-Item –path X:\NanoServer C:\NanoServer –recurse

Normally at this point, we would use DISM or Mount-WindowsImage against the file, and then begin adding packages by using Mount-WindowsImage, Add-WindowsDriver, and Add-WindowsPackage.

Here’s the trick…

There are currently 15 packages available to be added to the NanoServer.wim file. For all the various combinations of the server, you’ll have a massive pile of scripts.

With the New-NanoServerWim cmdlet you can run a quick Get-Help to see the available options:

Image of command output

This cmdlet assumes that a folder called C:\NanoTemp is your default destination, and it will create it for you to add the NanoCustom.wim file.

The only mandatory parameter is the location of the Nano Server media folder. To target the Nano Server source on drive C (if you copied it there), you would run the following command:

New-NanoServerWim –MediaPath ‘C:\’

This will take some time because it mounts the file and default to the following packages:

  • Compute (Hyper-V and Containers)
  • Clustering
  • GuestDrivers (Hyper-V Guest integration)
  • OEMDrivers (basic drivers)
  • Defender (Windows Defender)
  • DSC (Desired State Configuration client)

But this is not the only configuration. All of the remaining parameters are switches. If you’d like to build out the name Nano Server with IIS and File Storage added, run:

New-NanoServerWim –MediaPath C:\ -Storage –IIS

If you don’t want Hyper-V running, you must specify a $False parameter for the Compute switch:

New-NanoServerWim –MediaPath C:\ -Storage –IIS –Compute:$False

When the process is complete, one object is returned—the path and file name of the new customized Nano Server WIM file.

From this point, you could create as many different combinations as you want for basic WIM files for a virtual machine template or physical server.

If you’d prefer to create the custom WIM file in a different folder, you simply need to supply a different destination path, for example:

New-NanoServerWim –MediaPath C:\ -Storage –IIS –Compute:$False –Destination C:\OtherTempNano

In every case, it created a file called NanoCustom.wim in this release of the module. You’ll have to rename it if you don’t want it overwritten. The ability to use unique file names and prompt for overwrites may be part of a later release.

To organize all the various cabs together, I went with a very simple If/Then for each switch. This is not necessarily the best approach—but it does work (and it keeps the updating to a very simple cmdlet).

Stop in tomorrow as I look in to easily creating an Unattend.xml file for this image. This will allow automatically naming the Nano Server and joining to a domain (if needed) in a pretty seamless manner.

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.

Sean Kearney, Honorary Scripting Guy, Cloud and Datacenter Management MVP

Comments (4)

  1. iXlinQ says:

    Dear Sean,

    you are filling in for Ed again … wonderful … but where is Ed? Holliday journey araound the globe ?

    Well anyway: I’m running a WIN 8.1 x64 Enterprise OS and I have all the Windows 8.1 and 10 ADK available.
    If I run NewNanoServerWin, I’m receiving DISM Version Errors like this one:

    Add-WindowsPackage : Zur Wartung dieses Windows-Images ist die aktuelle Version der DISM erforderlich. Die aktuelle DISM-Version finden Sie unter

    "http://go.microsoft.com/fwlink/?LinkId=293395".

    Informationen zur Installation der aktuellen DISM-Version aus dem ADK auf dem Computer finden Sie unter

    "http://go.microsoft.com/fwlink/?LinkId=293394".
    In C:Program FilesWindowsPowerShellModulesDeployImage1.6DeployImage.PSM1:627 Zeichen:9
    + Add-WindowsPackage -PackagePath "$($MediaPath)NanoServerPack …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Add-WindowsPackage], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.AddWindowsPackageCommand

    Anything I could do now? Can I install a new DISM Version on my machine somehow, without breaking any Windows 8.1 functionality?

    Greetings, Klaus

  2. @XlinQ

    I’m taking a long shot as I tested this all on Windows 10 but I ran into similar issues with DISM modules before. I’ll need to add a sequence to force it to load the DISM module from the Windows ADK first. If you’re on Windows 8.1, even though there is a newer
    DISM module, it’s defaulting to the old one.

    To load the 64bit DISM module embedded in the ADK I believe this is the Command line

    Import-module C:Program Files (x86)Windows Kits10Assessment and Deployment KitDeployment Toolsamd64DISMDism.psd1

    Try loading that first to see if it works better 🙂

    Sean

  3. BeeLove says:

    Good stuff so far!!

  4. I’m working in the latest version of Windows 10 and when I run the command New-NanoServerWim –MediaPath ‘C:\’ everything runs fine for a few minutes then I get a whole bunch of these. Seven of them to be exact. It doesn’t stop the script and I do get a new wim in the nanotemp folder.

    Add-WindowsPackage : Invalid package path
    At C:\Program Files\WindowsPowerShell\Modules\DeployImage\1.21\DeployImage.PSM1:809 char:9
    + Add-WindowsPackage -PackagePath “$($MediaPath)NanoServer\Pack …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Add-WindowsPackage], PSArgumentException
    + FullyQualifiedErrorId : Add-WindowsPackage,Microsoft.Dism.Commands.AddWindowsPackageCommand

Skip to main content