g.pickardou
g.pickardou

Reputation: 35822

Save-AzureRmVMImage mandatorily creates invalid blob container name

I am capturing an ARM VM image to use it in create from image operations. However the Save-AzureRmVMImage command creates mandatorily (or just by default?) such a container and blob name what seems to be invalid for other commands.

The parts of "/Microsoft.Compute/ in the container name and "osDisk.xxxx" in the blob name are implicitly placed by the Save-AzureRmVMImage command.

To clarify: I used the Save-AzureRmVMImage -DestinationContainerName 'vhds' -VHDNamePrefix 'template'... but the command creates the container system/Microsoft.Compute/Images/vhds + "invents" the blobname which contains the osdisk. (dot) part. Both of them are not coming from me... and can not be prevented-

First of all this name seems to be not usable in the New-AzureRmVM operation. (see my detailed description at Creating new ARM VM from captured image: Blob name in URL must end with '.vhd' extension error

As a workaround to the error described above I found out that I will copy theimage to an other blob name which does not contains . (dot). However it turned out that my fully tested and otherwise working copy script also throws error for that blob name...

Copy source code (again, it is fully functional for other blobs)

(note: This question about the Save-AzureRmVMImage issue, or how it can its weird and invalid name workarounded in subsequent operations. So the question is not about this copy script. The script here is just demonstrating a diagnostic experience.

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

Full error message:

[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]  

Upvotes: 1

Views: 498

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136146

The reason your code is failing is because the container name you're specifying in your script is invalid. Please see this link for a valid container name: https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx.

Based on the information you provided in comments above, please try the following:

$sourceContainerName = "system"
$sourceBlobName = "Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd

Upvotes: 2

Related Questions