Last month I posted an article about the upcoming version of Nano Server which is to be released as part of Windows Server 2016.
I was attempting to make the process of creating a new Virtual Nano Server instance as quickly and easy as possible for testing out ASP.Net Core Websites.
Although I'd managed to script most of the work in PowerShell, so creating a new image only took a few commands, I still knew that improvements could be made.
Creating the image was relatively painless, but once the image was created and started there were some additional commands which needed to be run directly on the Nano server machine to configure IIS. Even though I'd scripted this, it still seemed messy, and something that could potentially be improved.
Thankfully, Microsoft have just announced the latest release of Windows Server 2016, which is Technical Preview 5. Creating images using this new technical preview is still very similar to Technical Preview 4, but there are a few additional improvements which make this initial configuration easier.
The new -SetupCompleteCommands parameter allows additional setup commands to be passed into the image, which automatically become included in the SetupComplete.cmd script which is automatically executed when the Server first starts up.
Using the process I'd described in my previous article, I can now pass the command to run my setup.ps1 script as a Setup complete command, which means it will automatically be run on first boot, so I don't have to manually login to the server to run this command.
Setting up the files
I'm setting up my local files for creating Nano server images in a very similar way to my previous post, so I'm not going to go into the same level of detail, but only explain the additional steps here.Previously I'd created a c:\nano folder containing a number of folders with the setup files. For the new version, you're going to need mostly the same files.
I've started by creating a new c:\nano5 (for Technical Preview 5), and I've created an ISO folder in there, into which I coped the entire contents of the Windows Server 2016 Technical Preview 5 ISO.
Also from the ISO's NanoServer folder you'll need to copy the NanoServerImageGenerator folder into c:\nano5.
I've also copied my Tools folder from my previous c:\nano folder into c:\nano5. The tools folder contains the HTTPPlatformHandler files, the output folder for your ASP.Net Core website, and the setup.ps1 script which we created in the previous post.
So in my c:\nano5 folder now, I've got an ISO, NanoServerImageGenerator and Tools folder.
Creating a Nano Server VM
The creation of the VM is very similar to how it was previously, but some of the command parameters have changed slightly. The previous -GuestDrivers parameter has been replaced by -DeploymentType Guest, and the -ReverseForwarders command is no-longer needed as this is done automatically. Also -MergeFiles has been replaced by -CopyFiles.First we need to import the NanoServerImageGenerator module.
>Import-Module \NanoServerImageGenerator
Then we can execute the new command to create the VM, with the additional parameter which will add our startup script to the SetupComplete tasks.
>New-NanoServerImage -Edition Standard -DeploymentType Guest -MediaPath .\ISO
-BasePath .\Base -TargetPath c:\Nano5\Nano1\Nano.vhdx
-ComputerName Nano1 -Packages Microsoft-NanoServer-IIS-Package
-EnableRemoteManagement -CopyFiles .\Tools
-SetupCompleteCommands 'powershell "& ""C:\Tools\Setup.ps1"""'
Note that the additional quotation marks around the path in the SetupCompeteCommands are needed.
This command will prompt you for an admin password, and after a couple of minutes you'll have a new Nano server VM hard drive image. A new Virtual machine can easily be created from this image with the same PowerShell commands as I'd use previously or using the Hyper-V Manager.
When the machine first starts the C:\Tools\Setup.ps1 setup script will automatically be run, which creates the necessary IIS configuration and firewall rules for your ASP.Net Core website to run, and then once the machine has fully started you should be able to browse the website by pointing your browser to the IP of the new server on port 8000.
This is a much nicer and neater method of creating a new Nano Server VM, and doesn't require any of the remoting into the server to execute scripts.
Windows Server 2016 is still a Technical Preview so some of this will probably change again, but hopefully it'll make this process even easier. Also .Net Core still hasn't shipped, so more changes are coming which may mean this works slightly differently in future.
I've added a new script on GitHub to streamline this new process. Nano-CreateTP5 can be executed as one command for creating, configuring and starting the VM.
