How to assign an IP for Hyper-V virtual machine using PowerShell?

13,021

You can use PowerShell Direct to connect to the VM directly from the Hyper-V Host. PowerShell Direct uses the VM bus to talk to the inside of the VM (as long as it runs a current windows). It bypasses the network stack and is made for exactly this. Needs really newish OS though (it says preview, but look at the date - predates Server 2016).

Then you can just change the IP address....

https://www.howtogeek.com/112660/how-to-change-your-ip-address-using-powershell/

Command(s) look like this:

New-NetIPAddress –InterfaceAlias “Wired Ethernet Connection” –IPv4Address “192.168.0.1” –PrefixLength 24 -DefaultGateway 192.168.0.254

Or you use DHCP ;) But that is not what you ask ;)

Share:
13,021

Related videos on Youtube

Matthew Tipton
Author by

Matthew Tipton

Updated on September 18, 2022

Comments

  • Matthew Tipton
    Matthew Tipton over 1 year

    I'm working with the Hyper-v and have created a VM using Vagrant. Seems to be in the Vagrantfile I've forgotten to define an IP address (static or dhcp use).

    Now I can view the info about the VM's network adapter.

    get-vm -n 2012R2 | Select -ExpandProperty NetWorkAdapters
    

    And the result info is the next:

    Network Adapter False 2012R2 VM Virtual Switch 00155DFA9F01 {Degraded, ProtocolVersion} {}
    

    As you can see the MAC address is defined, the switch is the external one. But the last property value (which relates to the bound IP-address) is NOT defined.

    Does exist the way to set manually the IP address for the VM machine in Hyper-V using Powershell or even GUI manager (didn't find possibility to set an IP in GUI).