I have followed the guidelines on how to manage virtual machines using C# and could create a sample program based on it.
However, In addition I have a use case where we want to clone multiple virtual machines and manage them remotely using a console program written in C#. I could find the ways to clone a VM via power shell, but I could not find anywhere how can I create a clone and eventually manage the cloned VM on Azure.
Can anyone please give me a direction on how I can use .Net SDK to achieve this use case?
Thanks
We can do that with Microsoft.Azure.Management.Fluent and WindowsAzure.Storage.
I create a demo for it and it works correctly for me. The following is my detail steps.
As you mentioned link. Firstly we need to deallocate the VM. Before that we need to get authentication to operation resource in the Azure.
1.Get Azure object using an authentication file, how to create an authentication file please refer to document. Before that we need to registry an Azure AD Application and assign corresponding role for it, more details please refer to the document. Then we can get the clientId, key(secret key) and tenant from the Azure AD App. The file format as following
Create the Microsoft.Azure.Management.Fluent.Azure object
2.Deallocate the VM with C# code.
3.Get the VM Disk Vhd uri Info with code
4.From the vhduri then we can get Storage Account and blobname.
5.Start to copy blob to the target container, more details about operating blob please refer to the document.
6.Create the Disk for creating vm
7.Create the VM and check from the Azure portal
packages.config file