2

I'm trying to setup a new resource group complete with a storage account and a container. All steps work except the container part. From resources online I've read that this API functionality is not ported to the new ARM cmdlets -- are there workarounds available?

Attempt #1

Login-AzureRmAccount

Set-AzureRmContext -SubscriptionName "Visual Studio Professional"

$resourceGroup = "MyResourceGroup4"
$location = "West Europe"

New-AzureRmResourceGroup -Name $resourceGroup -Location $location

Write-Host "Created resource group"

New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName "xzcczxda" -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
New-​Azure​Storage​Container -Name "images" -Permission Off

Error:

New-​Azure​Storage​Container : The term 'New-​Azure​Storage​Container' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Attempt #2 (based on this)

same as before but adding Import-Module AzureRM.Storage and using New-​AzureRm​Storage​Container instead.

Error:

New-​AzureRm​Storage​Container : The term 'New-​AzureRm​Storage​Container' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Attempt #3 (based on this and this)

Login-AzureRmAccount

Set-AzureRmContext -SubscriptionName "Visual Studio Professional"

$resourceGroup = "MyResourceGroup9"
$location = "West Europe"
$storageAccountName = "teststorageaccount"

New-AzureRmResourceGroup -Name $resourceGroup -Location $location

Write-Host "Created resource group"

New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage

Write-Host "Fetching storage account information"
$storageKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey

New-​Azure​Storage​Container -Name "images" -Permission Off -Context $storageContext

Error:

Get-AzureStorageKey : ResourceNotFound: The storage account 'teststorageaccount' was not found. New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. New-​Azure​Storage​Container : The term 'New-​Azure​Storage​Container' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Attempt #4 (based on this)

Login-AzureRmAccount

Set-AzureRmContext -SubscriptionName "Visual Studio Professional"

$resourceGroup = "MyResourceGroup10"
$location = "West Europe"
$storageAccountName = "dasdaaadmb"

New-AzureRmResourceGroup -Name $resourceGroup -Location $location

Write-Host "Created resource group"

New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage

Write-Host "Fetching storage account information"
$storageKey = (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroup).Value[0]
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey

New-​Azure​Storage​Container -Name "images" -Permission Off -Context $storageContext

Error:

New-​Azure​Storage​Container : The term 'New-​Azure​Storage​Container' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Attempt #5 (based on this)

Login-AzureRmAccount

Set-AzureRmContext -SubscriptionName "Visual Studio Professional"

$resourceGroup = "MyResourceGroup11"
$location = "West Europe"
$storageAccountName = "addadadsadad"

New-AzureRmResourceGroup -Name $resourceGroup -Location $location

Write-Host "Created resource group"

New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroup

New-​Azure​Storage​Container -Name "images" -Permission Off

Error:

New-​Azure​Storage​Container : The term 'New-​Azure​Storage​Container' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


At this point I'm out of ideas. How can I create a storage container from an ARM context? This seems to indicate the issue is because I'm mixing ASM and ARM which I hoped would've been resolved by passing around the context (see attempt 3 & 4)

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
  • +100 for persistence! One weird thing I noticed is when I copied the command from your question and pasted in PS, I got the following (look at the special characters) - https://i.stack.imgur.com/YohGP.png. I am wondering if this has something to do with the error you're getting. Can you just try by manually typing in `New-​Azure​Storage​Container -Name "images" -Permission Off`? – Gaurav Mantri Jul 13 '17 at 11:37
  • @GauravMantri I gave that a shot and retyped it manually but that didn't change anything. That said, when I just type that line in itself then I get the error "*New-AzureStorageContainer : Could not get the storage context. Please pass in a storage context or set the current storage context.*" which indicates that it works in isolation. – Jeroen Vannevel Jul 13 '17 at 12:29
  • So when you typed in manually, you got storage context error and not the cmdlet not recognized error. Correct? I think we're getting somewhere. From your attempt #4, can you type in 2 lines of code above this (i.e. where you get the key and create the context) along with this 3rd line (so all 3 lines manually). See if that makes any difference. – Gaurav Mantri Jul 13 '17 at 12:37
  • @GauravMantri You got it! I've added an answer detailing my findings. – Jeroen Vannevel Jul 13 '17 at 14:29
  • Awesome! I am glad I was able to help. – Gaurav Mantri Jul 13 '17 at 14:38

1 Answers1

1

Credit goes to @GauravMantri for figuring it out!

When I re-type everything word-by-word it works perfectly. I've adapted my original script and it ran without issues.

Following that I had a look at what the two strings consisted off.

void Main()
{
    var correct = "New-AzureStorageContainer -Name \"images\" -Permission Off -Context $storageContext";
    var wrong = "New-​Azure​Storage​Container -Name \"images\" -Permission Off -Context $storageContext";


    for (var i = 0; i < Math.Max(correct.Length, wrong.Length); i++)
    {
        Console.Write("correct: " + (int) correct[i]);
        Console.WriteLine("\twrong: " + (int) wrong[i]);
    }
}

I have highlighted where the two strings diverge.

enter image description here

Which brings me to this question: "What's HTML character code 8203?" with the magical answer "It's the Unicode Character 'ZERO WIDTH SPACE' (U+200B)."

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170