Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 376
Mohamed Uvais M Avatar asked Dec 14 '22 03:12

Mohamed Uvais M


2 Answers

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

like image 99
Ivo Haagen Avatar answered Jan 14 '23 00:01

Ivo Haagen


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
like image 36
Aatif Akhter Avatar answered Jan 14 '23 00:01

Aatif Akhter