Move a Microsoft Azure VM to a Different Subnet Within a vNet
Asked Answered
C

3

5

Can't we Move a Microsoft Azure VM to a Different Subnet Within a vNet using the azure new portal or the azure classic portal ? if not possible through portal then how to do so ?then how to edit the properties of a VM after creation, like moving to a different subnet,, etc.,?

Crandale answered 8/9, 2016 at 10:44 Comment(1)
This question has already been answered here - #35349666Pankey
N
11

It is possible through the new portal. First I want to ask you if you're using a Classic VM or a Resource manager VM. If you're using the last one you can easily switch between subnets by changing the configuration settings. go to your network interface > Ip configurations and click on the Nic name (see picture below)

View nic Azure

A new tab will open and you can change the Subnet of the nic.

Change Subnet

Nonnah answered 9/9, 2016 at 14:13 Comment(0)
P
2

If your vm is a classic one, moving it to different vNet is very easy using azure powershell cmdlets. Here is the code-

$vmName  = "xxxxx"
$srcServiceName  = "xxxxx"
$newVNet = "xxxxx"

# export vm config file
$workingDir = (Get-Location).Path
$sourceVm = Get-AzureVM –ServiceName $srcServiceName –Name $vmName
$global:vmConfigurationPath = $workingDir + "\exportedVM.xml"
$sourceVm | Export-AzureVM -Path $vmConfigurationPath

# remove vm keeping the vhds and spin new vm using old configuration file but in a  new vNet
Remove-azurevm –ServiceName $srcServiceName –Name $vmName
$vmConfig = Import-AzureVM -Path $vmConfigurationPath 
New-AzureVM -ServiceName $srcServiceName  -VMs $vmConfig -VNetName $newVNet -WaitForBoot
Pankey answered 9/9, 2016 at 20:38 Comment(1)
This question has already been answered for ARM vm - #35349666 I am adding my answer here as this deals with classic vmPankey
C
0

if not possible through portal then how to do so ?then how to edit the properties of a VM after creation, like moving to a different subnet,, etc.,?

It could be done with Powershell. In brief, it contains 3 steps:

  1. Get the VM (NIC) configuration
  2. Edit the VM (NIC) configuration
  3. Update the edited configuration

Note: Moving VMs between different VNET is not supported. To move the VM to another VNET, the only solution for now is re-create the VM with the same vhd file.

Here is a good step-by-step guide:

How to change Subnet and Virtual Network for Azure Virtual Machines (ASM & ARM)

Chipboard answered 9/9, 2016 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.