stricjux
stricjux

Reputation: 1404

Azure Power Shell - How to change network subnet

I'm trying to change an existing VM deployed via Resource Manager in Azure. The VM is configured with a wrong VirtualNetwork / Subnet. Changing this via portal.azure.net is not possible.

I've managed to retrieve the required network adapter by running: $adapter = Get-AzureRmNetworkInterface -Name xxxxx -ResourceGroupName xxxxx.

I can see the current configured subnet id via $adapter.IpConfigurations.Subnet and I've retrieved the new subnet via $net = Get-AzureRmVirtualNetwork -ResourceGroupName xxxxx -Name xxxxx.

I tried changing the $net.IpConfigurations.Subnet.Id = $net.Subnets.Id but I get a failure :

Subnet default referenced by resource xxxx is not the same Virtual Network ....

Can anybody tell me how to change the virtual network that a network adapter is using if it was deployed using Resource Manager (the "Classic" has the simple Set-Subnet command).

Upvotes: 2

Views: 5107

Answers (1)

Jack Zeng
Jack Zeng

Reputation: 2267

Changing the Virtual Network for an exiting ARM deployed VM is not possible. But, changing the subnet for a VM is quite easy.

  1. Login the Azure Portal
  2. In Resource groups, choose the resource group your VM is in.
  3. Choose your VM in the resources list of your resource group.
  4. in Setting blade of your VM, and choose Network Interfaces. enter image description here
  5. Select the network interface you want to change, and click IP Address. enter image description here
  6. Choose a Subnet, and specify an IP address, or choose Dynamic Assignment. enter image description here
  7. If none of the exiting subnets meets your requirement, click your Virtual network to create a new subnet. enter image description here

If you really want to change the Virtual Network of your VM, you can backup your OS Disk, and create a new VM with the OS Disk, and of course with the desired Virtual Network.

Upvotes: 8

Related Questions