1

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]  
Community
  • 1
  • 1
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • As the error indicate, the name of your blob container `system/Microsoft.Compute/Images/vhds` is invalid. It should be `vhds`. I would recommend exploring the contents of the storage account using a storage explorer to see the correct name for your blob container and the blob. – Gaurav Mantri Mar 08 '16 at 10:33
  • I gave _explicitly_ the 'vhds'. (Save-AzureRmVMImage -DestinationContainerName 'vhds'...) but the command creates the container system/Microsoft.Compute/Images/vhds. Insane I know. – g.pickardou Mar 08 '16 at 10:41
  • ...and its there. I used the azure portal blob properties (copy clipboard) facility to insert the full url to to my script... – g.pickardou Mar 08 '16 at 11:02
  • Can you share the full URL of the blob? – Gaurav Mantri Mar 08 '16 at 11:46
  • The https will not seen in the SO comment, and I've changed the real storage name to "mystorage" "https://mystorage.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd" – g.pickardou Mar 08 '16 at 12:01
  • Thanks. Please try to use `system` for blob container name and `Microsoft.Compute/Images/vhds/template-osDisk.be7b0cf4-a28b-47f9-89c7-43887f1570ab.vhd` for blob name and see if that makes any difference. – Gaurav Mantri Mar 08 '16 at 12:17
  • Thanks it works for Start-AzureStorageBlobCopy so this is an answer, please post it :-). – g.pickardou Mar 08 '16 at 12:31

1 Answers1

2

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
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241