Skip to content

Instantly share code, notes, and snippets.

@ned1313
Created May 15, 2015 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ned1313/37b78f1d8058cec92ab0 to your computer and use it in GitHub Desktop.
Save ned1313/37b78f1d8058cec92ab0 to your computer and use it in GitHub Desktop.
Script to create a Nano Server VHD from Windows Server Technical Preview 2
<#
Create-NanoServerVM.ps1
Script by Ned Bellavance
This script is intended to take the Nano Server WIM file and transform it to a usable VHD with
the correct drivers for running as a Hyper-V guest. The necessary files for the Nano Server
come from the Server Technical Preview ISO. This should be mounted on the E: drive, otherwise
change the E: to wherever the ISO is mounted. This script should be run as an Administrator.
The script also assumes an internet connection to pull down the Convert-WindowsImage.ps1 script
from the script gallery. The VHD created from the process is intended to be run as a Version 1
VM in Hyper-V. The NIC will receive an IP address from DHCP.
Version 0.1 - 5/15/2015
First version of the script
#>
#Copy all NanoServer files from the ISO
cp E:\NanoServer\ C:\ -Recurse
cd C:\NanoServer
#Copy the Convert-WindowsImage.ps1 file from the TechNet script gallery
Invoke-WebRequest -Uri "https://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f/file/59237/6/Convert-WindowsImage.ps1" -Method Get -OutFile Convert-WindowsImage.ps1
#Make the dism folder and copy over the dism files for Windows 10 images
md dism
cp E:\sources\api*downlevel*.dll .\dism
cp E:\sources\*provider* .\dism
cp E:\sources\*dism* .\dism
#Create the VHD file from the WIM and make a copy of it intended for Hyper-V
.\Convert-WindowsImage.ps1 -SourcePath .\NanoServer.wim -VHD .\NanoBaseEd1.vhd -VHDFormat VHD -Edition 1
cp .\NanoBaseEd1.vhd .\NanoBaseEd1-HyperV.vhd
#Create content and stream in drivers and SetupComplete.cmd file to image
Add-Content -Path .\SetupComplete.cmd -Value "ipconfig /renew"
md mountdir
.\dism\dism.exe /Mount-Image /ImageFile:.\NanoBaseEd1-HyperV.vhd /Index:1 /MountDir:.\mountdir
.\dism\dism.exe /Add-Package /PackagePath:.\packages\Microsoft-NanoServer-OEM-Drivers-Package.cab /Image:.\mountdir
.\dism\dism.exe /Add-Package /PackagePath:.\packages\en-US\Microsoft-NanoServer-OEM-Drivers-Package.cab /Image:.\mountdir
.\dism\dism.exe /Add-Package /PackagePath:.\packages\Microsoft-NanoServer-Guest-Package.cab /Image:.\mountdir
.\dism\dism.exe /Add-Package /PackagePath:.\packages\en-US\Microsoft-NanoServer-Guest-Package.cab /Image:.\mountdir
md .\mountdir\Windows\Setup
md .\mountdir\Windows\Setup\Scripts
cp .\SetupComplete.cmd .\mountdir\Windows\Setup\Scripts
.\dism\dism.exe /Unmount-Image /MountDir:.\MountDir /Commit
#Show the files
explorer.exe C:\NanoServer
#Script Complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment