3

I have a HyperV switch. When I run hnsdiag list networks, the following is returned:

03D8864D-7F72-412C-AC60-CC3056A1AE11
Name: staticip
Type: Internal
Subnet Address: 172.31.224.0/20
Gateway: 172.31.224.1

How can I change the Subnet Address and Gateway?

I found "Install-Module -Name HNS" so I have the "Get-Hns" and "Remove-Hns" functions. I was expecting "Set-Hns" functions.

I tried to connect network adapters to the virtual switch with IP addresses in the range that I expected (not the addresses returned by hnsdiag).

I looked in the registry. I found the virtual switch and its subnet and gateway in binary data. I was expecting to find a string registry value to modify.

Greg Askew
  • 39,132

1 Answers1

0

Unfortunately, the Set-Hns cmdlet is not available, but you can use the New-HnsNetwork cmdlet to create a new network with the desired settings and then just remove the old one.

Here's how you can do it, as simple as I can put it:

Get the current network object:

$network = Get-HnsNetwork -Name "staticip"

Create a new network with the desired settings:

$newNetwork = New-HnsNetwork -Name "staticip" -Type Internal -SubnetAddress "172.31.240.0/20" -Gateway "172.31.240.1"

Replace the subnet address and gateway with your desired values.

Remove the old network:

$network | Remove-HnsNetwork -Force

This will remove the old network with the original settings.

Verify the changes:

hnsdiag list networks

This should now display the updated subnet address and gateway for the "staticip" network.

Note: Be cautious when modifying network settings, as it may affect existing virtual machines and connections, and remember to update any dependent virtual machines or network adapters accordingly.