如何获取 Azure 托管磁盘的 VHD?

2024-01-09

我创建了一个带有托管磁盘的虚拟机。默认情况下,托管磁盘不再存储在 Blob 存储中。问题是我现在需要 osdisk 的 vhd 文件,但我无法找到正确的方法来检索它。

我找到的唯一方法是在 azure 门户中打开磁盘,然后按“导出”创建 vhd 文件的下载链接。这种方法是不受欢迎的。


您可以使用 PowerShell 将托管磁盘的 VHD 复制/导出到存储帐户

#Connect to Azure and set your azure subscription

#Declare Variables
$resourceGroupName = 'xxxxx-rg'
$snapshotName = 'xxxxxx.md'
$resourceGroupNameStorageAccount = 'xxxx-rg'
$storageAccountName = 'xxxx-storage'
$storageContainerName = 'xxxxx'
$destinationVHDFileName = 'xxxxxx.vhd'

#Get the Storage Account Key of the Destination Storage Account
$storageAccountKey = Get-AzStorageAccountKey -resourceGroupName $resourceGroupNameStorageAccount -AccountName $storageAccountName

#Generate the SAS for the snapshot
$sas = Grant-AzSnapshotAccess -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -DurationInSecond 3600 -Access Read

#Create the context of the destination storage account for the snapshot
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey ($storageAccountKey).Value[0]

#Copy the snapshot to the destination Storage Account
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何获取 Azure 托管磁盘的 VHD? 的相关文章

随机推荐