How To Silently Deploy Windows Server 2016 To A Hyper-V Virtual Machine (VM) With PowerShell

In this video, Adam will go over all the steps it takes to deploy Windows Server 2016 from an ISO file to a Hyper-V VHD using nothing but an ISO file and an answer file..oh..and a little bit of help from a WIM2VHD script.

In this tip you going to learn about how to deploy Windows Server 2016 silently to a hyper V VM so first off if you pre requisites. We need to talk about we're going to expect you to have an ISO file of the Windows Server 2016 image. I get mine from the visual studio subscriber downloads, you can get this from any channel that you need and also you're going to need the product key of this so you go into need to insert. The product key inside of the answer file along with a lot of other information will show you in for the answer file. I directly on my hyper V host and I would be running all commands directly from that. OK, the first thing we need to talk about is the hyper V VM. We need a VM obviously to run the operating system that we're going to be deploying this case. I'm just running new VM from PowerShell. I've already done this and created a VM called lab DC actually let's go over here and verify. I do have a lab DC VM created so you can see here alright. So now that we have the VM created then we go about the answer file the answer file has all of the logic and all of the complicated settings and everything. That's required to make this happen. I'm just doing the easy easy part. Now there may be another snip in the future about how to understand these answer files, but I've already got one created and if you're not familiar with the answer file how to create one a good resources to use the windows answer file generator as you see here. You can specify all the different settings. Everything that will be applied when the Windows operating system gets installed so feel free to do that. You have a lot of different options here for operating systems and software and whatnot so. Since I've already created the answer file here is just a brief summary of what it does, I'm not going to go over these in specific at all. But here's kind of a list of what this answer file does as I mentioned the answer boxing be customized and created an any different ways that you want. But these are just some of the settings that you'll see in the answer file which is available in the GitHub repo for you to download and customize as you see fit. It is called lab TC, dot XML. Cape next thing you need is the convert Windows Image Script. This is another one that does a lot of the heavy lifting for us? See this is a script variable on the technet script center. And is called Convert Windows image dot PS1 or wim to VHD. This is very complicated. It's a really, really big script and it does a lot of great stuff for us. It's able to take a wim, or an ISO directly and then apply the answer file to windows and then essentially deploy. The Windows operating system directly from an ISO file. It's we're going to hear so highly encourage you to do that the URL to do that is. Here on Line 48 if you need to get that. The script has a function inside of it, so you need to dot source, it to make the function available. Once you outsource it there's a plethora of parameters that you can provide to it, but the important ones are the source path as I'm providing here. That's the path of the Windows Server ISO an the Unattend Path, which is the path of the answer file that I have created everything else for the most part is what you want to do. I'm setting my VHD size to 40. Gigabytes is going to be server. Standard core and specifying the VHD path type. This partition style. All that stuff can be modified, but the most important ones are the source path to the ISO. And the unattended path of the answer file that I have created and if you need an example. That's going to be in the GitHub Repo Alright. So now that we have all the parameters defined. We're going to pass to this function. I'm just going to grab all those and grab the function call that function and then now you can see that it's going to provide some logging output is going to open the ISO that inside of the eye. So it looks for that. Wim file so it extracts. The ISO looks for the wim selects the image inside of the wim, which is server. Standard core then it goes about creating the VHDX attaching it going through all the partitioning like it needs to go in through the system formatting with this part as you can see. Then it's also going to sign the system and boot volume and then finally it's going to sit in this applying image to VHDX for awhile because this is going to take a little while so and then once it's done then at that point we simply need to attach it to the VM. But we will do that whenever this is done so stand by for just a second. All right now that you can see that it is done. It is closed. The VHDX close the windows image thing close the ISO and then now it's done. So now we should have a VHDX with Windows Server 2016 installed next thing we need to do is Mount that VHDX to the VM. We just created before so to do that in line 70 through 75. Here, I'm first getting the VM so getting that VM object for lab DC and then using the add VM hard disk drive to attach it to that. VM that I'm setting the boot order to make sure that the VHDX that were attaching is 1st. In the boot order using these set VM Firmware Command. So let's go over to our VM here and then go to the settings and make sure everything looks OK. So the firmware boot from hard drive the value is lab DC that's good. And here is the hard drive so the hard drive is attached and it is lab DC dot VHDX alright next step. Now we boot it up and hope it all works at this point now that you're booting it up the hard work is pretty much over if everything works. Well, the VM will simply boot into Windows Server 2016 and then start the setup process getting gathering all the answers from the answer fail and once that happens if you're pretty much done. But there's a lot of things that go wrong in here that's why it took me awhile to get the answer file. So hopefully this all works just fine and if it does you can then grab all of the my hard work from the GitHub repo and this work for yourself, OK looks like it was successful notice that it went through some of these setup process. It went through all of those set up creating the user account, setting the DNS server properties. Setting some firewall settings. You notice that it did that at first that got all of that information from the answer file. So now that it's put it up in server core since I set auto login. It did log in as my lab user account at this point we are done. So there's not much to actually making that happen actually deploying it but all of the logic is in that answer file and then also that really important. Convert Windows Image script, so that has been how to silently deploy Windows Server 2016 to a hyper V VM thanks for watching.