Skip navigation
Modify IP Configuration of VM from Hyper-V Host

Modify IP Configuration of VM from Hyper-V Host

Q: How can I modify the IP configuration of a virtual machine (VM) from the Hyper-V host?

A: Windows Server 2012 introduced the ability to inject IP configuration into a VM from the Windows Server 2012 or later Hyper-V host, using the virtualization\v2 WMI namespace. This was required for the Hyper-V Replica functionality that enables an alternate IP configuration to be injected into a VM during a replica failover.

To perform the injection using Windows PowerShell, do the following, which leverages the Msvm_GuestNetworkAdapterConfiguration class (

Replace the name of the VM as needed and the IP configuration.

$vmName = "win81g2" 

$Msvm_VirtualSystemManagementService = Get-WmiObject -Namespace root\virtualization\v2 `
    -Class Msvm_VirtualSystemManagementService 

$Msvm_ComputerSystem = Get-WmiObject -Namespace root\virtualization\v2 `
    -Class Msvm_ComputerSystem -Filter "ElementName='$vmName'" 

$Msvm_VirtualSystemSettingData = ($Msvm_ComputerSystem.GetRelated("Msvm_VirtualSystemSettingData", `
    "Msvm_SettingsDefineState", $null, $null, "SettingData", "ManagedElement", $false, $null) | % {$_})

$Msvm_SyntheticEthernetPortSettingData = $Msvm_VirtualSystemSettingData.GetRelated("Msvm_SyntheticEthernetPortSettingData")

$Msvm_GuestNetworkAdapterConfiguration = ($Msvm_SyntheticEthernetPortSettingData.GetRelated( `
    "Msvm_GuestNetworkAdapterConfiguration", "Msvm_SettingDataComponent", `
    $null, $null, "PartComponent", "GroupComponent", $false, $null) | % {$_})

$Msvm_GuestNetworkAdapterConfiguration.DHCPEnabled = $false
$Msvm_GuestNetworkAdapterConfiguration.IPAddresses = @("")
$Msvm_GuestNetworkAdapterConfiguration.Subnets = @("")
$Msvm_GuestNetworkAdapterConfiguration.DefaultGateways = @("")
$Msvm_GuestNetworkAdapterConfiguration.DNSServers = @("", "")

$Msvm_VirtualSystemManagementService.SetGuestNetworkAdapterConfiguration( `
$Msvm_ComputerSystem.Path, $Msvm_GuestNetworkAdapterConfiguration.GetText(1))


Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.