我正在捕获一个ARM VM映像,以便在从映像操作创建时使用它。 但是,Save-AzureRmVMImage命令强制创建(或者只是默认情况下?)这样的容器和blob名称似乎对其他命令无效。
容器名称中的" /Microsoft.Compute/部分和" osDisk.xxxx" blob名称中的内容由Save-AzureRmVMImage命令隐式放置。
澄清:
我使用了Save-AzureRmVMImage -DestinationContainerName 'vhds' -VHDNamePrefix 'template'...
但该命令创建了容器 system / Microsoft.Compute / Images / vhds +" invents"包含 osdisk的blobname。 (点)部分。他们两个都不是来自我......而且无法阻止 -
首先,这个名称似乎在New-AzureRmVM操作中不可用。 (请参阅Creating new ARM VM from captured image: Blob name in URL must end with '.vhd' extension error
上的详细说明作为上述错误的解决方法,我发现我会将图像复制到另一个不包含的blob名称。 (点)。然而事实证明,我的完全测试和其他工作副本脚本也会抛出该blob名称的错误...
复制源代码(同样,它完全适用于其他blob)
(注意:关于Save-AzureRmVMImage问题的这个问题,或者它在后续操作中如何处理其奇怪和无效的名称。所以问题不在于这个复制脚本。这里的脚本只是展示诊断经验。 / p>
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"
$sourceRgName = "rg-wp"
$sourceName = "mystorage"
$sourceContainerName = "system/Microsoft.Compute/Images/vhds" #the dots seems to be invalid
$sourceBlobName = "template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd" #the dots seems to be invalid
$destinationRgName = "rg-wp"
$destinationName = "mystorage"
$destinationContainerName = "vhds"
$destinationBlobName = "template.vhd"
$sourceKeys = Get-AzureRmStorageAccountKey -Name $sourceName -ResourceGroupName $sourceRgName
$destinationKeys = Get-AzureRmStorageAccountKey -Name $destinationName -ResourceGroupName $destinationRgName
$contextSource = New-AzureStorageContext -StorageAccountName $sourceName -StorageAccountKey $sourceKeys.Key1
$contextDestination = New-AzureStorageContext -StorageAccountName $destinationName -StorageAccountKey $destinationKeys.Key1
Start-AzureStorageBlobCopy -Context $contextSource -SrcContainer $sourceContainerName -SrcBlob $sourceBlobName -DestContext $contextDestination -DestContainer $destinationContainerName -DestBlob $destinationBlobName
# Wait for copy to complete
Get-AzureStorageBlobCopyState -Context $contextDestination -Container $destinationContainerName -Blob $destinationBlobName -WaitForComplete
完整的错误消息:
[ERROR] Start-AzureStorageBlobCopy : Container name 'system/Microsoft.Compute/Images/vh
[ERROR] ds' is invalid. Valid names start and end with a lower case letter or a number
[ERROR] and has in between a lower case letter, number or dash with no consecutive dash
[ERROR] es and is 3 through 63 characters long.
[ERROR] At D:\work\.vsonline\Azure\PowerShell\PowerShell\copy blob.ps1:40 char:1
[ERROR] + Start-AzureStorageBlobCopy -Context $contextSource -SrcContainer $sourceConta
[ERROR] ine ...
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] ~~~
[ERROR] + CategoryInfo : NotSpecified: (:) [Start-AzureStorageBlobCopy],
[ERROR] ArgumentException
[ERROR] + FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure.
[ERROR] Commands.Storage.Blob.Cmdlet.StartAzureStorageBlobCopy
[ERROR]
答案 0 :(得分:2)
您的代码失败的原因是您在脚本中指定的容器名称无效。请参阅此链接以获取有效的容器名称:https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx。
根据您在上述评论中提供的信息,请尝试以下操作:
$sourceContainerName = "system"
$sourceBlobName = "Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd