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

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

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)
A new tab will open and you can change the Subnet of the nic.

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

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:
Get the VM (NIC) configuration
Edit the VM (NIC) configuration
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)

Related

How to check if a vpn gateway is connected to a vnet through powershell script

I want to check if a vpn gateway connection is given to a vnet through a powershell command given a vnet name.
I have created 2 vnets in 2 different resource groups and enabled peering.
You can use command in following manners
First get virtual network object from azure from following command:
Vnet_object = Get-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup
"Vnet_object" will be of type "PSVirtualNetworkGateway"
Pass this object in following command and you will get virtual network gateway if it is connected to that Vnet.
Get-AzVirtualNetworkGatewayVpnClientConnectionHealth
-InputObject
Link for above command: https://learn.microsoft.com/en-us/powershell/module/az.network/get-azvirtualnetworkgatewayvpnclientconnectionhealth?view=azps-2.4.0
If I'm not understanding you correctly, please let me know. It seems that you want to know if a VNet has gateway connected when you have enabled VNet peering.
You could use Azure PowerShell (Get-AzVirtualNetwork -ResourceGroupName $myrg -Name $myVnet).VirtualNetworkPeerings, then you will check the value of parameter AllowGatewayTransit and UseRemoteGateways. One of those values is true, this vNet has a connecting gateway.
Additionally, the new Az module is used for Azure Resource Manager model, it's recommended to migrate Azure PowerShell from AzureRM to Az. If you still use the old AzureRM module, you could replace Get-AzVirtualNetwork with Get-azurermVirtualNetwork.

migrating existing Azure VMs to Azure Premium Storage

i am having two VM'S which is under domain running erp application and database server. Both vm are in Standard D12 v2 (4 cores, 28 GB memory)template.
Now we need to move these VM's into premium disk. So How can i migrate existing Azure VMs to Azure Premium Storage.
I will recommend migrating to Managed Disk and you can migrate existing VMs using standard storage account to Managed Disk and Premium Storage account follow article below.
Migrate existing Azure VMs using standard unmanaged disks to Premium managed disks
We can migrate existing Azure VMs from standard storage account to Premium storage account, but we need to shutdown the VMs.
If we can shutdown the VMs, then we can follow those steps to migrate them:
1.Via Azure portal to create a premium storage account(new).
2.Shutdown Azure VMs, copy VHDs to premium storage account. we can use PowerShell, Azure storage explorer or Azcopy to copy VHDs to new storage account.
3.Just delete Azure VMs and keep the VHDs, Virtual Network, NIC, Public IP address and other settings.
4. Use new storage account to create new VMs, when we create new VMs, in the configure page, we select original Vnet and NIC to it.
5. After it complete, try to login those VMs and test
erp application, make sure that the VMs to run properly, then delete original VHDs and storage account.
Note:
When we use VHDs from new storage account to create VMs, we need to select VM disk type to SSD.
===========================================
Update:
1. stop Azure VM and delete the VM via Azure portal.
2. use Azcopy(Microsoft Azure storage command line) to copy VHD to new Azure premium storage account:
AzCopy /Source:https://vmdisks416.blob.core.windows.net/vhds /Dest:https://jasondisk999.blob.core.windows.net/vhds /SourceKey:key /DestKey:key /Pattern:jasonvm20170519131021.vhd
3. Use PowerShell to create new Azure VM:
PS C:\Users> $rgname = "vm"
PS C:\Users> $loc = "eastus"
PS C:\Users> $vmsize = "Standard_DS1_v2"
PS C:\Users> $vmname = "jason-newtest2"
PS C:\Users> $vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize
PS C:\Users> $nic = Get-AzureRmNetworkInterface -Name "jasonvm422" -ResourceGroupName $rgname
PS C:\Users> $nicId = $nic.Id
PS C:\Users> $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId
PS C:\Users> $osDiskName = "jason-newtest"
PS C:\Users> $osDiskVhdUri = "https://jasondisk999.blob.core.windows.net/vhds/jasonvm20170519131021.vhd"
PS C:\Users> $vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -Linux
PS C:\Users> New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm
WARNING: Since the VM is created using premium storage, existing standard storage account, vmdiag614, is used for boot diagnostics.
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK

How to capture an image of Azure virtual machine in new portal?

I have a bizsparkplus subscription. I followed the below link but could not find the capture button:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-capture-image/#next-steps
Any suggestions?
Until yesterday, I found nothing in Azure's new portal that can help capture an image from a VM,
but today, out of the blue, I found a "Capture" button right inside the VM's Overview tab :) (will appear only for VMs with "Managed Disks")
It is super easy to capture an image (takes like a minute), but you have to connect ssh on the VM first & run this command (which will delete user's home folder) as per this official article:
sudo waagent -deprovision+user -force
then you can use the button.
-- Warning --
Capturing an image from your VM will stop it and mark it as generalized which won't let you start this VM ever again, because being generalized is an irreversible process "by design"! .. the Sh***y thing is, they didn't even put a warning on the button!, so be careful with that!
This feature is not available yet in the new Azure Portal. You have to options : Azure Resource explorer or PowerShell.
Here is an example in powershell. In this example the custom image will be saved in the VM storage account. The vm custom image will be stored in the following location "System/Microsoft.Compute/Images/templates/***.vhd". :
$vmResourceGroup = "iaas-rg";
$vmName = "ubuntu";
$destinationContainerName = "templates";
$vhdNamePrefix = "template";
$sampleOutupTemplatePath = "C:\Templates\ImagesGeneralized\sampleOutputTemplateUbuntu.json";
Login-AzureRmAccount
#Dellocate the VM
Stop-AzureRmVM -ResourceGroupName $vmResourceGroup -Name $vmName
#Generalize the vm
Set-AzureRmVM -ResourceGroupName $vmResourceGroup -Name $vmName -Generalized
# Save the custom vm Image
Save-AzureRmVMImage -ResourceGroupName $vmResourceGroup -VMName $vmName -DestinationContainerName $destinationContainerName -VHDNamePrefix $vhdNamePrefix -Path $sampleOutupTemplatePath
The second option is to use Azure Resource Explorer, you can execute the operations manually * :
*To execute those operations, the mode "read/write" must be selected in Azure Resource Explorer.
Regards,
You can able to capture the classic virtual machines in new portal. There is an option for capturing. attaching is the screenshot.
In case anyone else looking for this topic, I was researching it and found some azure docs here:
Create a managed image of a generalized VM in Azure
which explains generalizing is a one way operation (and why)
and how to deal with that by creating a VM copy first
Create a Windows VM from a specialized disk by using PowerShell
Using the option 3 in the article.

Migrate classic Azure resources to new Azure resource manager

After switching to the new Azure portal, I see all resources of mine are listed as classic resources. I am googling around to see if it's possible to have classic VM and migrate it to ARM and just hadn't seen anything that stated it was possible.
I tried deleting the class VM but keep the VHD to check if I can attach it to the ARM VM. The result said it doesn't work.
Is there any way that can be used to achieve this ?
Unfortunately (and strangely!) there isn't a way to do this via the portal and you have to drop down to Powershell instead (or xplat / Rest)
When I have exported VMs from v1 to v2 I typically make the original vhd file accessible via a blob share (this can be done temporarily for the duration of this command)
You can then deploy a new VM using that vhd as a source image's URI, using
Set-AzureRmVMOSDisk -VM $vm -Name $vmname -VhdUri $uri -CreateOption FromImage -Windows
Alternatively you can copy the vhd to v2 storage and use Attach instead of FromImage
If you wrap that around a standard VM Create script, you should be good to go!
There is a set of powershell scripts to assist in migrating classic vms to the new resource group model - asm-arm
They require the Azure and AzureRM powershell modules - msdn link to installation instructions

Azure: DNS change after VM setup

I recently setup Active Directory on a VM inside an Azure Virtual Network. Unfortunately, the Virtual Network DNS entry was not put in before creating and working with the Active Directory VM.
Because of Azure's framework, I believe I have to recreate the VM (after making the DNS change). Does anyone know how to take a snapshot of the virtual hard-drive and re-associate that with a newly created VM after the DNS change is made. I have read information about sysprep to capture an image but I'm afraid that will corrupt various AD settings.
Also, does anyone have any other information about this type of DNS change?
Thanks,
akgh
Here are the steps:
First export the VM configuration to an XML file
get-azurevm -servicename [service name] | export-azurevm -path [local path]
This generates a small XML file that contains information about the VM.
Next, remove the VM configuration from Azure.
remove-azurevm [VM name]
This does not actually delete the VHD file, it only removes the configuration about the VHD that you have previously backed-up/exported from step 1. So there is no danger or destruction done here. These are actually the same steps you would do if you wanted to stop paying for the service.
Now, restore the VM configuration with the new DNS settings you want.
$dnslocal=New-AzureDNS -Name "my Azure DNS Server" -IPaddress "192.168.10.4"
$dnsonprem=New-AzureDNS -Name "my OnPrem DNS Server" -IPaddress "172.16.83.21"
Import-AzureVM -Path 'E:\myVM.xml' | New-AzureVM -ServiceName 'myVM' -Location 'West US' -DnsSettings $dnslocal,$dnsonprem -VNetName "MyVNET" –AffinityGroup “CATAFF1”
Note: You may get an error when trying to import the VM configuration. If you get an error that the DNS name already exists, then you may need to remove the cloud service
remove-azureservice –servicename “myVM"

Resources