I’m writing a utility to move vms between 2 azure tenants.
I’m developping it in C# as part of a larger project.
Microsoft provides instructions in powershell:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/disks-upload-vhd-to-managed-disk-powershell
It seams pretty straightforward but I can’t find how to get the SAS urls of the source and destination in c#.
$sourceDiskSas = Grant-AzDiskAccess -ResourceGroupName $sourceRG -DiskName $sourceDiskName -DurationInSecond 86400 -Access 'Read'
$targetDiskSas = Grant-AzDiskAccess -ResourceGroupName $targetRG -DiskName $targetDiskName -DurationInSecond 86400 -Access 'Write'
What rest apis or nuget packages and classes should I use to achieve the same in c#?
I searched for quite a long time and didn’t find a documented solution on the web?
2
Answers
You can use this Disk Grant Access REST API
https://learn.microsoft.com/en-us/rest/api/compute/disks/grant-access?tabs=HTTP
The below is the NuGet used for Azure SDK for .NET.
Using C# code