Mohamed Uvais M
Mohamed Uvais M

Reputation: 305

Move a Microsoft Azure VM to a Different Subnet Within a vNet

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.,?

Upvotes: 5

Views: 27621

Answers (3)

Ivo Haagen
Ivo Haagen

Reputation: 111

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

Upvotes: 11

Aatif Akhter
Aatif Akhter

Reputation: 2206

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

Upvotes: 2

Steven Lee - MSFT
Steven Lee - MSFT

Reputation: 810

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)

Upvotes: 0

Related Questions