Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

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

$
0
0

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 Part 2 of a five-part series. Also see Use DeployImage Module and PowerShell to Build a Nano Server: Part 1.

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


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>