Migrate classic Azure resources to new Azure resource manager - azure

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

Related

How to get the azure VMUUID of azure VM?

I am creating an ARM template for the Azure Log Analytics workspace.it has some queries which use azure VM's VMUUID. Is there is any way to fetch the azure VM's VMUUID inside the ARM template or any other way to fetch azure VMUUID?
ARM Template I just need to get the values of VMUUID of all VM's in that subscription.
You can also get this information programmatically from the Azure Instance Metadata Service (IMDS). It provides information about currently running virtual machine instances. You can use IMDS to manage and configure your virtual machines. This information includes the SKU, storage, network configurations, and upcoming maintenance events. For a complete list of the data available, see the Endpoint Categories Summary.
IMDS is a REST API that's available at a well-known, non-routable IP address 169.254.169.254. You can only access it from within the VM. Communication between the VM and IMDS never leaves the host.
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service
Try Azure Resource Explorer
You could easily find it in the Azure Resource Explorer.
//One more extra reference: What is Azure Resource Explorer?
Just navigate to the Microsoft.Compute => virtualMachines view:
There is one more way to find it, but for me seems more complicated as you need to connect to the VM:
https://azure.microsoft.com/en-us/blog/accessing-and-using-azure-vm-unique-id/
Update: Try PowerShell
The simple PowerShell script below returns a list of all VMUUIDs in the specified subscription:
Get-AzSubscription
Select-AzSubscription -SubscriptionId "Olga's Subscription"
$GetVM = Get-AzVM
Foreach ($vm in $GetVM)
{
$vmId =""
$vmId = $vm.vmid
$vmIdList +=$vmId + "`r`n"
}
Write-Output $vmIdList
Please let me know if above answers your question.

Manage Microsoft.ClassicCompute/domainNames with Az PowerShell module

I have a classic Compute resource. I need to move some old deployment code that used Azure.Service module to Az and I was wondering, is there a way to manage that with Az or something up to date?
I have to upload some .cspkg and some .cscfg files. There is more to it, but basically, this was done using this cmdlet and the related ones, Set, Get etc.
I used Az.Resources' cmdlet New-AzResource to create it:
New-AzResource `
-Location 'location' `
-ResourceGroupName 'rgName' `
-ResourceType 'Microsoft.ClassicCompute/domainNames' `
-ResourceName 'rName' `
-ApiVersion '2018-06-01'
What cmdlets could I use to manage this resource?
In your case, you could use Az.CloudService module commands, to upload some .cspkg and some .cscfg files, use New-AzCloudService with parameters -PackageUrl and -ConfigurationUrl(or -Configuration).
The command New-AzCloudService can Create or update a cloud service, i.e. New, Set operations, to do Get operation, use Get-AzCloudService command.
Anyway, see here for all the commands to manage Microsoft.ClassicCompute/domainNames i.e. Cloud service, use them depends on your requirement.
Update:
In this case, looks you could not migrate your commands to Az module, Az.CloudService is for the new Cloud Service(extended support) which is ARM(Azure Resource Manager) based, and it is in the preview version, see Deploy a Cloud Service (extended support) using Azure PowerShell, some features might not be supported, I think the error was caused by this.
What you are using is Cloud Service(classic), it is ASM(Azure Service Management) based, the new Az module is just for ARM resources.
So in your case, you may need to continue to use Azure.Service module, or you can migrate the ASM to ARM i.e. Cloud Service(classic) to Cloud Service(extended support), see Migration to Azure Resource Manager, but not recommend you to use it in the production environment as it is in preview.

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

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.

How do I create a powershell script to clone a vm in RM

I have created 2 Virtual Machines (VMs) using RM (Resource Manager) deployment method. How can I clone a VM using Azure PowerShell scripts?
You can follow the documentation guide here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-capture-image/
After you Open the Azure PowerShell and login to your Azure account.
You can find the subscriptions your Azure account has by using the command Get-AzureRmSubscription.
Next you will need to deallocate the resources used by this virtual machine.
Stop-AzureRmVM -ResourceGroupName YourResourceGroup -Name YourWindowsVM
Next you need to set the status of the virtual machine to Generalized. Note that you will need to do this because the generalization step above (sysprep) does not do it in a way that Azure can understand.
Set-AzureRmVm -ResourceGroupName YourResourceGroup -Name YourWindowsVM -Generalized
Next, Capture the virtual machine image to a destination storage container using this command.
Save-AzureRmVMImage -ResourceGroupName YourResourceGroup -VMName YourWindowsVM -DestinationContainerName YourImagesContainer -VHDNamePrefix YourTemplatePrefix -Path Yourlocalfilepath\Filename.json
The -Path variable is optional and can be used to save the JSON template locally. The -DestinationContainerName variable is the name of the container that you want to hold your images in. The URL of the image stored will be similar to https://YourStorageAccountName.blob.core.windows.net/system/Microsoft.Compute/Images/YourImagesContainer/YourTemplatePrefix-osDisk.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.vhd. It will be created in the same storage account as that of the original virtual machine.
The Azure documentation offers a detailed guide to do this, so follow the instructions and in case of trouble, you can ask me!
BEWARE! When you sysprep your machine and make it generalized, you CANNOT UnDO this!!!
This means that you VM will stay stopped (deallocated) and you can create infinite cloned from this, but you cannot start this again, so make sure it is not in production :)

Resources