【问题标题】:Creating a Storage Container from an ARM context从 ARM 上下文创建存储容器
【发布时间】:2017-12-18 03:28:21
【问题描述】:

我正在尝试设置一个包含存储帐户和容器的新资源组。除容器部分外,所有步骤均有效。从在线资源中,我了解到此 API 功能未移植到新的 ARM cmdlet —— 是否有可用的解决方法?

尝试 #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

错误:

New-​Azure​Storage​Container:术语“New-​Azure​Storage​Container”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并尝试 再次。

尝试 #2(基于 this

与以前相同,但添加 Import-Module AzureRM.Storage 并改用 New-​AzureRm​Storage​Container

错误:

New-​AzureRm​Storage​Container:术语“New-​AzureRm​Storage​Container”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并 再试一次。

尝试 #3(基于 thisthis

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

错误:

Get-AzureStorageKey:ResourceNotFound:未找到存储帐户“teststorageaccount”。 New-AzureStorageContext:无法验证参数“StorageAccountKey”上的参数。参数为 null 或空。提供一个不为 null 或空的参数,然后重试该命令。 New-​Azure​Storage​Container : 术语“New-​Azure​Storage​Container”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并尝试 再次。

尝试 #4(基于 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

错误:

New-​Azure​Storage​Container:术语“New-​Azure​Storage​Container”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并尝试 再次。

尝试 #5(基于 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

错误:

New-​Azure​Storage​Container:术语“New-​Azure​Storage​Container”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并尝试 再次。


在这一点上,我没有想法。如何从 ARM 上下文创建存储容器? This 似乎表明问题是因为我正在混合 ASM 和 ARM,我希望可以通过传递上下文来解决(参见尝试 3 和 4)

【问题讨论】:

  • +100 持久性!我注意到的一件奇怪的事情是,当我从您的问题中复制命令并粘贴到 PS 中时,我得到了以下信息(查看特殊字符)-i.stack.imgur.com/YohGP.png。我想知道这是否与您遇到的错误有关。你可以手动输入New-​Azure​Storage​Container -Name "images" -Permission Off试试吗?
  • @GauravMantri 我试了一下并手动重新输入了它,但这并没有改变任何东西。也就是说,当我自己键入该行时,我收到错误“New-AzureStorageContainer:无法获取存储上下文。请传入存储上下文或设置当前存储上下文。”表示它是独立工作的。
  • 因此,当您手动输入时,您会收到存储上下文错误,而不是 cmdlet 无法识别错误。正确的?我认为我们正在取得进展。从您的尝试 #4 中,您能否在此上方输入 2 行代码(即您在哪里获取密钥并创建上下文)以及第 3 行(因此手动所有 3 行)。看看这是否有什么不同。
  • @GauravMantri 你明白了!我添加了一个详细说明我的发现的答案。
  • 太棒了!我很高兴能够提供帮助。

标签: powershell azure azure-storage azure-powershell


【解决方案1】:

感谢@GauravMantri 解决这个问题!

当我逐字重新键入所有内容时,它会完美运行。我已经修改了我的原始脚本,它运行起来没有问题。

接下来我看了一下这两个字符串的组成。

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]);
    }
}

我已经突出显示了两个字符串的分歧点。

这让我想到了this question:“什么是 HTML 字符代码 8203?”和神奇的答案“It's the Unicode Character 'ZERO WIDTH SPACE' (U+200B).

【讨论】:

    猜你喜欢
    • 2021-04-24
    • 2015-04-01
    • 2022-07-19
    • 2011-02-24
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2023-04-05
    相关资源
    最近更新 更多