The Newton Lab – How it’s built

I’ve used my lab for years. ¬†Many have heard me say how this lab has saved me so much time over the years…it’s paid for itself several times ūüôā

Often times I need to test a migration or other configuration for a client (or just test some new software). ¬†This lab is made up of a single server (desktop case) here’s the basic specs (it’s all on the cheap):

thenewtonlab-blog

After many rebuilds over the years between running full installs of Windows 2012 and Windows Hyper-V Server , I’ve finally settled on installing all host OSs to boot from VHD. ¬†This makes sure the drive letters stay consistent across the OSs (I previously would dual boot between Windows Server 2012 direct on the boot disk and a boot from VHD Windows Hyper-V Server).

With the host done I built a VM to run as a Remote Desktop Gateway. ¬†I use the “Quick Session Collection”. ¬†To gain access remotely I use a free (yes free) cert from StartSSL.com. ¬†All you need is a registered domain and you can get a free cert (you need to validate that you own the domain via confirmation email). ¬†So let’s say you own newton.com (I wish I did Apple…’cause you’re not using it right now). ¬†You can then request a server cert for remote.newton.com and install that on your internal RD Gateway. ¬†Then you’ll need to add a host name in the newton.com zone that points to the public IP of your home router…and you should be good to go. ¬†Many ISPs today will not keep your IP the same overtime and so you’ll need to update the A record you created. ¬†For that I use a free service from DNSExit. ¬†Just transfer your DNS ¬†zone and you can use client software that will monitor the external IP and update it as needed.

A couple of other notes…. ¬†I now only publish the “Server Manager” app and then launch Hyper-V Manger from there (it’s good to keep things simple)…in previous builds I would publish all the management tools separately.

Windows Server 2016 has changed things up for Hyper-V – one of which is the configuration files. ¬†I was running the Tech Preview 5 for quite awhile and then earlier this week decided to move to the RTM build and plan to use a script my good friend @foxdeploy wrote that would simply export the XML files for each VM. ¬†I then would take those files to import back to Hyper-V (the VHDs are not changing location)…but this¬†didn’t work with Windows Server 2016 which now uses VMCX files.¬†So I decided to create my own script to export the VM configs to a file and then re-import.

function Export-VMs {
 [CmdletBinding()]
 param(
 [Parameter(Position=0)][string]$VMHost,
 [Parameter()][string]$Output = "vm-export-cfg.csv")

 $vms = get-vm -ComputerName $VMHost
 foreach($vm in $vms){

 $properties =[ordered] @{'VMName'=$vm.name;
 'VMDisk1'= Get-VMHardDiskDrive -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty path -first 1;
 'VMDisk2'= Get-VMHardDiskDrive -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty path -last 1;
 'VMSwitch1'=Get-VMNetworkAdapter -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty Switchname -first 1;
 'VMSwitch2'=Get-VMNetworkAdapter -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty Switchname -last 1;
 'VMDynRAM' = Get-VMMemory -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty DynamicMemoryEnabled;
 'VMRAMMin' = Get-VMMemory -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty Minimum;
 'VMRAMStartup' = Get-VMMemory -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty Startup;
 'VMRAMMax' = Get-VMMemory -ComputerName $VMHost -VMName $vm.name|select -ExpandProperty Maximum;
 'VMGen' = $vm.Generation}
 $object = New-Object ‚ÄďTypeName PSObject ‚ÄďProp $properties
 Write-Output $object|export-csv $output -NoTypeInformation -Append
 }#end foreach $vm
}#end function 

function Import-VMs {
 [CmdletBinding()]
 param(
 [Parameter(Position=0)][string]$VMHost,
 [Parameter()][string]$input = "vm-export-cfg.csv")

$vmconfigs = import-csv $input
 foreach($vm in $vmconfigs){
 #create VM
 new-vm -ComputerName $VMHost -Name $vm.VMname -MemoryStartupBytes $vm.VMRAMStartup -VHDPath $vm.VMDisk1 -Generation $vm.VMGen -SwitchName $VM.VMSwitch1
 #Enable Dynamic Memory
 if($vm.VMDynRAM -eq $true){
 Get-VM -Computername $VMHost -Name $vm.VMName|Set-VMMemory -DynamicMemoryEnabled $True
 }

 #add second disk if needed
 if($vm.VMDisk1 -ne $vm.VMDisk2){ #need to add second disk
 Get-VM -ComputerName $VMHost -Name $vm.VMName|Add-VMHardDiskDrive -Path $vm.VMDisk2
 }
 #add second Nic if needed
 if($vm.VMSwitch1 -ne $vm.VMSwitch2){
 Get-VM -ComputerName $VMHost -Name $vm.VMName|Add-VMNetworkAdapter -SwitchName $vm.VMSwitch2
 }
 }#end foreach $vm
}#end function

I take the export file and save it off the host server and then rebuild the server as a new Hyper-V host and then run the import and boom all the VMs are there (man i love PowerShell).

 

Anyway I hope someone finds this helpful in their lab building. ¬†In a future post I’ll cover how a setup my multi-boot configuration and built the fresh new Nano server.

Happy building.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s