在DevTest实验室的Azure上运行sysprep后下载VHD

时间:2017-09-25 21:26:00

标签: azure azure-devtest-labs

我使用az lab vm apply-artifacts 命令在DevTest实验室的VM上运行了sysprep工件。

之后,当我运行az lab vm show时,我得到一个包含资源ID的computeId

计算ID看起来像:"computeId": "/subscriptions/#####/resourceGroups/###/providers/Microsoft.Compute/virtualMachines/####"

如何从中获取磁盘路径。我对SAS密钥更感兴趣,我可以在AzCopy中使用它来下载与此VM关联的vhd文件。

1 个答案:

答案 0 :(得分:0)

目前,Azure不支持使用Azcopy从devtest实验室下载VHD。

作为解决方法,我们可以从此VM 创建自定义映像(创建快照),然后使用PowerShell通过Azure PowerShell将此快照复制到另一个存储帐户。 enter image description here

然后我们可以使用此PowerShell复制此快照,以下是脚本:

#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"

#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"

#Provide the snapshot name 
$snapshotName = "yourSnapshotName"

#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"

#Provide storage account name where you want to copy the snapshot. 
$storageAccountName = "yourstorageaccountName"

#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"

#Provide the key of the storage account where you want to copy snapshot. 
$storageAccountKey = 'yourStorageAccountKey'

#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"


# Set the context to the subscription Id where Snapshot is created
Select-AzureRmSubscription -SubscriptionId $SubscriptionId

#Get the snapshot using name and resource group
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName 

#Generate the SAS for the snapshot 
$sas = Grant-AzureRmSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName  -DurationInSecond $sasExpiryDuration -Access Read 

#Create the context for the storage account which will be used to copy snapshot to the storage account 
$destinationContext = New-AzureStorageContext –StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey  

#Copy the snapshot to the storage account 
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName

有关此脚本的详细信息,请参阅此link

<强>更新

我们可以通过Azure门户创建图像,如下所示:

enter image description here