How to remotely connect to a Hyper-V virtual machine

17,522

But taking advantage of the topic, and if I did not have another IP address, how can I perform this procedure? Have some way to connect without a static IP?

As you might know, one simple way to connect remotely to a virtual machine is the Enter-PSSession cmdlet. For this method, if you seek to connect a host machine to a virtual machine on HyperV for remote purposes, you don't need any IP configs to be set.

A simple way to achieve this would be to write something like this, assuming you got virtual machines loaded in HyperV:

#Get all the virtual machines from hyperV
#And store them into an object
$virt_mach = Get-VM
#Try with one specific VM
#..You need to start it before
Start-VM -VM $virt_mach[0]
#To Access to a specific Vm with credentials 
#You need to define credentials like this (or with the get-credentials cmdlet)
$user = "DOMAIN\myuser1"
$password = ConvertTo-SecureString "SuperPasswordSoHaRdToFIND" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($user,$password)
#connect to the first VM of the list
Enter-PSSession -VMName $virt_mach[0].Name -Credential $creds
#and then write commandy you need to into the virtual machine
#in here..

To exit the PSSession, just type Exit-PSSession.

Please keep in mind that. This method of Virtual Machine connection ONLY works with O.S, which supports Powershell Direct, which means that this would only work with Windows 10 and Server 2016.

There is no way, in my opinion, to connect remotely to a windows 7 virtual machine from a host machine, other than configuring manually the setup you were talking about before (setting IP addresses, adding the virtual machine to trusted domains, etc.).

Share:
17,522

Related videos on Youtube

D3F4ULT
Author by

D3F4ULT

Updated on September 18, 2022

Comments

  • D3F4ULT
    D3F4ULT over 1 year

    I own a remote machine running Windows Server 2012, I created a virtual machine using Hyper-V, installed Windows 7, is possible remotely connect to this virtual machine? How do I do that? Using some other program?

    • CharlesH
      CharlesH over 9 years
      By remotely connection you mean you would like to remote desktop to the Windows 7 Virtual Machine? If so you can use remote desktop connection (MSTSC) from Windows as long as you have setup your networking correctly on both your Windows Server 2012 box and your Virtual Machine...
    • CharlesH
      CharlesH over 9 years
      Also is this remote connection on the LAN or from an external location (WAN)?
    • LPChip
      LPChip over 9 years
      I believe you can connect to a remote Hyper-V virtual machine using Hyper-V manager, but I do not know what is required to do this, so I won't post an answer. But it might help you or others to write an answer.
    • D3F4ULT
      D3F4ULT over 9 years
      @CharlesH , yes. I use Linux Mint, the remote computer is Windows Server 2012, so I created this for Hyper-V virtual machine to be accessed remotely by a friend of mine, so he can not change the files in the real machine. Connect to the local machine Hyper-V is easy, I just do not know when the connection is remote outside the network (which is my case), because it involves IP settings. Now I just saw the email setup they gave me 3 ips, I'll try right now, for one fixed IP on the virtual machine and try to connect, if it works, I leave the answer here later.
    • CharlesH
      CharlesH over 9 years
      You will need to set a static IP on the Windows 7 machine and also check you can browse the internet, etc that way you know you have access to the outside world. If that is the case then the virtual machine acts just like a physical machine on its static IP and can have a port forward setup on your router/firewall on port 3389 which will allow remote desktop connection. You also need to enable remote desktop connection in control panel > system > remote settings < allow connections from computers....
    • D3F4ULT
      D3F4ULT over 9 years
      Finally I managed to connect, now it worked, thanks for the comments helped me a lot, I set static IP and was. But taking advantage of the topic, and if I did not have another IP address, how can I perform this procedure? Have some way to connect without a static IP?