Link to home
Start Free TrialLog in
Avatar of hypercube
hypercubeFlag for United States of America

asked on

Install Server 2016 on a Hyper-V VM from command prompt.

I'm trying to set up a Windows Server 2016 Standard VM using Hyper-V with Command Prompt and PowerShell.

So far, I've been able to install Hyper-V and create a VM.
Now I need to install Server 2016 on the VM with GUI (using CLI/PS on Hyper-V).

I've not been able to find instructions for how to do the next step.
Where might that be found?

I HAVE found any number of instructions for how to do this if the Hyper-V GUI is running - but it isn't.
The idea was to be able to have 2 Server 2016 VMs on a single machine.
But, it's not going very quickly.

I guess I need to have an .iso for Server 2016 (which I probably already have).
And, I need to install from that onto the VM.
But I don't quite get how to launch that VM install process.

I'm happy to read things and would like to find something pertinent.
Avatar of Cliff Galiher
Cliff Galiher
Flag of United States of America image

You don't really install from the command line from the host. That would rather defeat the primary purpose people virtualize. The host doesn't directly access the VMs. The VM is still a machine and you need to connect to its virtual monitor (using a bit of hyperbole here) just like you connect a monitor to a physical machine so go through the setup screens.

If the host doesn't have a GUI, you'll probably want/need to do this remotely. A remote hyper-v console can be used to manage and connect to VMs.
If I do understand right you want to install Windows 2016 on VM you just created using PS right ??? (So no GUI)

Firts you must install DVD drive on VM then mount ISO image on this DVD


Command to add DVD

Run PS as Administrator

Now you must forward PS command to HV session to avoind add -computername to all commands

Let assume your HV server name is: HVServer

Enter-PSSession HVServer

Open in new window


You just said you VM is already created so you don't need command to create VM

Now you must install DVD on VM - if you still don't have it

I assume your VM name is VM1

Add-VMDvdDrive -VMName VM1

Open in new window


to confirm You have DVD drive on VM use command

Get-VMDvdDrive -VMName VM1

Open in new window


Remember or write down ControllerNumber and ControllerLocation

Now you must mount your ISO image.

Now I assume you have your W2016.ISO file under let say e:\ISO\ directory on your HVserver

Set-VMDvdDrive -Path "e:\ISO\W2016.ISO" -ControllerNumber 0 -ControllerLocation 1 -VMName VM1

Open in new window


Now all you need to do is Start VM1 to start installing Windows 2016

Start-VM -Name VM1

Open in new window



I think That's all
That'll start the VM with the ISO, yes.  It the VM will boot the ISO and sit there at a virtual setup screen waiting for input. It won't install windows.
No Cliff
From this moment it will start VM and ask to press any key to start Windows setup.
From now you can continue using W2016 setup screen with GUI

@Freed

You can watch video from ITDVDS.COM with tutorial how to do it:

https://www.youtube.com/watch?v=iopzjWsLZM4

After all remember to dismount ISO file to prevent run setup in loop.
I think you misinterpreted the question.  (Or I did.)

The OP has asked

"Now I need to install Server 2016 on the VM with GUI (using CLI/PS on Hyper-V)."
"I HAVE found any number of instructions for how to do this if the Hyper-V GUI is running but it isn't."  Emphasis mine

So he has a host without a GUI.  And he wants to install a guest and have the guest OS have the GUI enabled.

To which you wrote (to my response) "Which you wrote "From now you can continue using W2016 setup screen with GUI"

But the point is the OP doesn't have access to the setup screen which is why they are asking how to run setup via CLI/PS.

So again, since the host has no GUI (core presumably) the OP can't *ACCESS* the guest GUI from the host because the host has no GUI.  So I reiterate, your process will get the VM started, but will basically be sitting at a setup screen that the OP can't access. So I stand by my initial suggestion.  Using the Hyper-V Manager remotely will be easier than getting a customized ISO file mounted with an answer file or finding a CLI/PS solution to pass arguments to setup.exe after the fact.
As mentioned, the following PowerShell gets you into the VM's own PowerShell once the base OS has been installed:
$VMName = "MY-VMName"
Enter-PSSession -VMName $VMName -Credential $VMName\administrator

Open in new window

Once the VM has either been promoted as a DC or joined a domain the above would look like:
$VMName = "MY-VMName"
$DomainName = "Domain.Com"
Enter-PSSession -VMName $VMName -Credential $DomainName\administrator

Open in new window

Those are the two key methods for PowerShell Remoting into a VM on the host or on the network. No RDP into the VM or server on the network required.
Question is, why do it the hard way, Fred, what are you trying to win?
Just install RSAT on your machine, use the hyper-v mmc snapin to connect to your Host machine and that's that.
MCKnife - this is good training to prepare yourself to Windows Core ver. :)
Avatar of hypercube

ASKER

Thanks folks!
I feel like I'm wandering through a dense forest with a flashlight with instructions to "climb the Oak tree".
I'm not sure what an Oak tree looks like.
Nonetheless there's real progress.
Cliff Galiher described the situation pretty well.
McKnife:  Win??? It's the "hard way" because I'm still pretty ignorant / still learning the landscape and the language.
e.g. I just discovered the Hyper-V Management program on my workstation.  It looks like this could be really helpful.  I think it's what Cliff mentioned as a way to a virtual monitor??
Anyway, I haven't been able to log into the VM using it yet.... that's in progress or process depending on success fast or slow.

I have fairly modest Server requirements and would like to save money in the process.  Perhaps the money part is foolish.
I could simply install Windows Server 2016 Standard (with GUI) on a computer and be done with it.    That would be easy and then I could get on with the necessary testbed experience and experiments leading to real deployment.
Instead, I chose a Hyper-V install (which has no GUI itself) so I would gain a bit more experience and end up with two virtual servers (each with GUI) for the price of one - as I understand it.

So, I have Hyper-V installed and running and have PowerShell running within it.
I have two VMs defined - but none with an OS yet.
I have Hyper-V Management running on a workstation .. but can't connect to the Hyper-V/Servers

Nagging questions at this point:
If one is to connect to a VM with no OS, then how did it get an IP address?  
Somehow it seems there is work to be done from the CLI/PS interface on the Hyper-V/Server machine.....
You can't connect to a VM directly via TCP/IP if it has no OS.  It *has* to have an OS of some sort.  Whether that's an "installed" OS from media onto its virtual hard disk, or whether it is an OS booted from media (windows installation media runs an OS called Windows PE as part of the installation process), or an OS sent to the machine over the network (PXE boot, which itself has a small bootstrap OS to bring up the network and download the network OS.)

Which is where I saw you getting stuck and why you cannot pass setup arguments from the host to the guest with simple command lines.

You are on the right track though.  If you use Hyper-V Manager to connect to the host, the host can act as the liaison and pass the console (virtual monitor) session of the guest back to Hyper-V Manager on your management workstation.  The host does not need a GUI to do this, and you get the full GUI console view of whatever is on the guest, whether that's install media setup screens, or a fully running GUI OS.


You just need to connect to the host from Hyper-V Manager. If both machines (host and management workstation) are domain joined, this usually "just works."  If not, there is a bit of work to do; but this is well documented:

https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/11/11/configuring-remote-management-of-hyper-v-server-in-a-workgroup/
Nit picking little problems:
I can't get a PSSession to go from the workstation.  Get this
Enter-PSSession : Connecting to remote server SERVER failed with the following error message : WinRM cannot process
the request. The following error occurred while using Kerberos authentication: Cannot find the computer SERVER. Verify
that the computer exists on the network and that the name provided is spelled correctly. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession SERVER
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (SERVER:String) [Enter-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

Also, can't connect to the Hyper-V server with the Hyper-V Manager on the workstation.  Get this:
User generated image
Now, I must say that all of the computers are on a domain except the Hyper-V server.  Perhaps that's where it's failing.
I have tried setting up common users/passwords on the workstation and the HVSrv to no avail.
I hope You've ryn PS as administrator and you've used your hour VM Host name
This command you must run from the Host VM server not from workstation
Which command Tom?
In view of the errors I reported above, one issue seems to be that the Hyper-V Server isn't visible on the workstation's network.
I can ping its IP address from the workstation.
I have edited the hosts file on the workstation to associate the name with the IP address and can ping the server name as well.

There is the WinRM thing.
There is the Virtual Machine Management Service thing.
On the Hyper-V host:
IPConfig /registerdns

Open in new window

Make sure the DNS servers on the network have a DNS A record for the host listed properly.

I'm not sure if double hopping will work where
Enter-PSSession -ComputerName HOST --> Enter-PSSEssion -VMName VMName

Open in new window

but it's worth giving it a try.

If using the IP address when trying to PowerShell remote into the host then make sure to specify the local admin credentials
Enter-PSSession -ComputerName 10.0.0.10 -credential HVHostName\Administrator

Open in new window

Fred, let me understand,.
What name you want to assign to IP ?

VM itself when you will create doesn't have IP
If you will install Windows on VM then Windows has name and IP, or maybe I do not understand something
OK.  Thanks everyone!  I've used bits and pieces of all the advice.
I can now start a PSSession from the workstation at least.
I did have to add the Hyper-V Server as a TrustedHost on the workstation.....
And, of course, I can run PowerShell on the Hyper-V Server from a console of its own.
So far I don't see a difference in terms of what I'm trying to accomplish (install the OS on a VM).

Anyway, after setting up the .iso, starting the VM does nothing it appears except to start the VM.
I see nothing that would indicate that the .iso is being run.
So, it appears there's something missing as in:
How does the VM know to boot from the .iso and why is it an .iso instead of the files?

Tom: I think this answers your questions.  I've followed your instructions and the last step doesn't seem to be working (install the OS).
Can you post result when you use

Get-VMDvdDrive -VMName VM1

(replacve VM1 with your VM name)
User generated image
So now when you will turn on your VServer01 from HV Host setup is not starting automatically ?
Exactly.  That's what I tried to convey earlier and did ask some questions around it like: how does it know to boot from the VMDvd when it starts.  It doesn't seem to know that small detail....
Cliff Galiher:  In the mean time, I can't use Hyper-V Manager on the workstation to add a server.  That's the Virtual Manager Service thing....
VMHost is trying to run VM so it's looking for boot device. Since Disk is empty then should act like regular computer and go to next available device, CDROM/DVD

Are you sure your ISO is from regular W2016 installation, and not from Upgrade ?

Can you try mount different ISO, like W2012 to check ?
I don't know that the disk is empty.  I should think it would be but .....
How to know?
Fred,, You just said you've created new VM, so your Virtual Disk is EMPTY for sure
OK.  But I still can't get the install to happen it appears.  It happens just about instantaneously (the prompt comes back) and I see nothing to indicate.
Ok, check your BIOS (firmware) boot order

For VM 1st generation

Get-VMBios <virtual machine name> | Select-Object *

Open in new window


for VM 2nd generation

Get-VMFirmeare <virtual machine name> | Select-Object *

Open in new window


Please post result

then you can try change order

1st
Set-VMBios -VMName "Your VM Namer" -BootOrder $dvd,$vhd

Open in new window

2nd
Set-VMFirmware -VMName "Your VM Namer" -BootOrder $dvd,$vhd

Open in new window

Tom,  Revealing... there is one of each type so both commands were used:

User generated image
User generated image
We are talking about VServer01, so I see no DVD installed and you can't use it ad Boot device, so maybe this is your problem
I added another and here's what I get:
User generated image
So now try to check boot order and make sure DVD is on the list
It is not first,, make it first
Seriously guys. You're going the wrong way with this.  Think about a real server. What happens if you out in a setup DVD and start it up?

It starts, it boots the DVD, and the first setup screen waits for you to select language.  And it'll sit there and wait until you go through the srtup screens, partition the drive, etc.

Same here. Starting a VM will come back immediately (the VM is started.) But the I stall won't just magically run. You HAVE TO give it input. You need to use Hyper-v Manager, connect to the host, and then use that to connect to the console of the VM so you can interact with it.

You can't just initiate the install from the host. That will never work the way you think it will.
I am going to (Hopefully politely) suggest that you reinstall the gist with a GUI.

1) You haven't successfully set up a guest yet so there is no data loss.

2) There is a skill level to managing remotely, via command line, with kerb delegation that is missing here. That'll have a ripple effect in ongoing maintenance, patching, and disaster recovery

3) The resource savings of core is minimal in the given environment as described. Core has its place, but I don't think this is a good fit for it.

In short you are burning a ton of time and effort for a sub-par setup moving forward and gaining almost no benefit from attempting this convoluted setup.

You could have reinstalled the host and installed many VMs and be running for as long as this question has already been open. I recommend knowing when it is time to cut bait and make that decision now before losing more time.
Cliff Galiher:  What you say makes sense.  The only excuse is that this is a learning experience for me.
So, the perhaps naïve attempt was to use the Hyper-V Server installation (which has no GUI) and to install up to 2 Windows Server VMs with the one license.  That approach had been recommended.  So, I'm trying it.
The idea of saving a little money by having 2 VMs instead of one OS install may or may not make sense to you.  Does it?  I guess not from what you've said.

I appreciate your comment about maintaining such a system.  It's too optimistic to think that only the VMs will need to be managed once they are running.  I think that's the point.
So, given that I need a system with at least a DC at each of 2 sites, what would be the recommended lineup from your perspective?  Money does matter but time is money too!

Tom Cieslik:
I added a VMDvd but only see "Drives" here:
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Cliff Galiher
Cliff Galiher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cliff:  Interesting.  Thanks!
It makes me wonder why it would be mentioned or even offered this way?
There are legitimate benefits to core, but limited in a single-server or even a small-server environment.

Core has a slightly lighter footprint.  In a datacenter with high-density VMs, that can add up...datacenter power bills can be immense.

The lighter footprint can mean faster patching.  In a cluster where you patch round-robin and move 100s of VMs during the patching of dozens of hosts, that time savings can add up.  When you are temporarily hosting more VMs on other nodes as a node is being patched, getting all nodes back up and rebalancing is important.  This is usually automated, but still, in a datacenter it is important.  

The lighter footprint is arguably a smaller security footprint and thus more easily secured.  Again, in a datacenter, especially a hosting provider, this matters as that is many targets, not just one, and juicy targets too as a host houses many customers' data.  But it is *arguable* in that there are no documented cases of a GUI-specific component being used in a breach that core would have prevented.  Still, for the security conscious in a datacenter, it is worth it.

But all of these have one thing in common.  Datacenter scenarios; where they can pay full-time sysadmins to manage dozens or hundreds of physical servers remotely from a single management workstation/pane of glass.  These guys aren't logging into each host manually and managing that machine with powershell.  Guaranteed.  So core delivers benefits, but does so because the company using it can invest in automation and specialized IT Pros with the skill to write that automation one-time for other IT generalists to use.

For the average small shop, acquiring those skills is prohibitively expensive, or at the very least not a wise use of time.  Enthusiasts such as myself have done it, and as I've now indicated several times (and have posted the blog to do so), you can remotely manage your server and get the guest VM installed with Hyper-V Manager without joining a domain.  But that takes effort and following those blog post instructions precisely, and probably some underlying understanding of why the steps work the way they do. Without that underlying knowledge, you are stuck wondering "should I have run this command on the host? On the guest? On the management workstation?"

...and due to social engineering, I *NEVER* recommend blindly following blog posts where you don't understand WHY the steps work the way they do.  It is just better to take a different approach altogether.  So, for most businesses, even for someone wanting to learn, installing the GUI is just a better option.  The times you'll need to manage a core machine are slim to none, so learning that skill is an act of sheer personal curiosity...which is why enthusiasts such as myself have done it.  The practicality of it, unless you want a job in a datacenter, is minimal.  And if you do want a job in a datacenter, you won't be dropped into the deep end like that.  As I said, they already have automation in place.  And if you are in line to be the guy writing that automation, you'll be getting *plenty* of on-the-job training in that datacenter and will learn this stuff in due time that no home lab can replicate.

Just my .02 cents.
Thanks all!.  I ended up bagging the CLI and installed the whole thing from scratch with the GUI.  Then added a couple of Servers with GUI as well.  Now I have what I wanted to be starting with...