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 1

$
0
0

Summary: Sean Kearney introduces his DeployImage module and the cmdlets for Nano Server.

Honorary Scripting Guy, Sean Kearney, is here this week giving Ed a little early holiday rest and showing you a bit about Nano Server.

One of the challenges we all need to deal with in our environments is security. One of the biggest security headaches is patching. Patching means one big headache: rebooting the server. The reason rebooting that server is a headache is that it often means an interruption in business operations or a critical application. Therefore, ideally the fewer reboots, the less downtime.

Nano Server jumps to a whole new level of server management. There is no GUI on the server. All management is done 100% via Remote Server Administration Tools (RSAT) and Windows PowerShell remoting.

Here’s the tricky part…Nano Server is really new. It’s still in testing along with Windows Server 2016.

In fact, it’s so that new the installer is a couple of PowerShell scripts and instructions on TechNet with a very long and detailed article about how to set up and deploy it.

With all this in mind (and wanting to use it on a physical server, and wanting others to easily do the same), I went about writing a sample script to deploy it to a partition structure in a virtual machine. It worked quite well, but a little bird tapped me on the shoulder and suggested flipping it into a module to allow for easy consumption in the PowerShell Gallery.

Which is where DeployImage comes in. It’s a new module that is available in the TechNet Script Repository, the PowerShell Gallery, and GitHub. It presently offers 13 new cmdlets, and it makes deployment of WIM files far easier. Presently, it runs in Windows 10 and Windows PowerShell 5.0. If anybody would like to try it in Windows 8.1 and Windows PowerShell 5.0, it should work.

This module can be found in the PowerShell Gallery under DeployImage and also on GitHub at energizedtech/DeployImage. The module introduces the 13 new cmdlets to simplify deploying Nano Server and WIM files to VHD, USB, and physical disk environments (Nano Server being the dominant reason). Here are the key cmdlets I’m going to use this week (I’ll also delve a bit into their code):

  • Get-AttachedDisk   
  • Clear-DiskStructure
  • New-PartitionStructure   
  • New-NanoServerWIM
  • New-UnattendXMLContent
  • Send-UnattendXML     
  • New-WindowsPEWim  
  • Send-BootCode

I’m going to presume that you have three key pieces to get started:

  • Windows Server 2016 TP4 ISO
  • Windows 10 ADK
  • A USB key

With these three pieces and the module, we’ll be building out everything we’ll need to deploy Nano Server on either a physical or a virtual machine.

To get started, in Windows 10, execute the following code (you must be running as an Administrator):

Find-Module DeployImage | Install-Module

If you’ve never downloaded code from the repository, you’ll be prompted to install some software. It’s complete OK to let it install.

Run the following command to make sure all is good with the module installation:

Import-Module DeployImage
Get-Command –module DeployImage

At this point, we have the module installed and operational. One of the things you can do now is execute the following cmdlet:

Test-WindowsADK

If the Windows 10 ADK was installed on a default path, you’ll get a Boolean $True response.

You can also try this cmdlet, which is a wrapper around the Get-Disk cmdlet with some options tossed in:

Get-AttachedDisk

By default this will return all internal physical disks. If you have a bunch of USB keys, you can execute this command to get a nice little menu and cherry pick one from the list:

$Disk=Get-AttachedDisk –USB –GUI

You can even properly wipe a disk with this cmdlet:

Clear-DiskStructure –disk $Disk

Although Clear-Disk will normally work, I’ve encountered some situations in which I had to remove all the partitions first, and then run Clear-Disk. All this cmdlet does is wrap some code to make the process more consistent.

In my module, I’ve added a little cmdlet called Remove-DriveLetter, which comes in handy if you try to image a pile of USB keys. You can remove the drive Letter from a partition to allow it to be reassigned afterwards, for example:

Remove-DriveLetter –DriveLetter L; #Removes Drive Letter L from its assigned Partition

The goal of the commands I use throughout this week is one task: To easily deploy any WIM file to a server, whether it is a physical or virtual machine.

Pop in tomorrow when we’ll take a look at what’s involved in creating the customized Nano Server WIM file with the DeployImage module.

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>