【问题标题】:Create 100 containers in two storage account for Azure Powershell or cloud shell在 Azure Powershell 或云 shell 的两个存储帐户中创建 100 个容器
【发布时间】:2018-12-03 05:28:28
【问题描述】:

我想在两个存储帐户中创建 100 个容器。如果我们选择手动过程是很乏味的。 一个是经典的,另一个是 RM 存储帐户。 (说真的,有时我会想我为什么要在 Azure 上这样做)

如何做到这一点。 1) 使用 powershell 对于 PS,我在 add-azureaccount 命令弹出窗口中遇到错误

谁能帮忙。

并且 2) 使用 Azure Cloud Shell 我如何使用 Azure Cloud Shell 来做到这一点

【问题讨论】:

  • 遗憾的是,您的问题中“咆哮”多于内容。也就是说:似乎您遇到了工具安装问题(powershell、cli),而不是实际的容器创建问题。在你的问题中,真的没有什么可以帮助解决这个问题的。仅供参考,在创建容器时,无论是使用经典还是 RM 存储帐户,都没有区别。此外,所有用于存储的特定语言 SDK 都支持创建容器,因此您可以在几行代码中执行此操作,循环遍历容器名称)。或者根据需要在您的应用程序中创建(在容器类上,有一个“如果不存在则创建”方法)
  • @DavidMakogonthanks。我再次编辑了问题。希望这有助于理解问题。
  • 如果您发布您尝试使用的脚本可能会有所帮助

标签: azure azure-storage azure-blob-storage powershell-3.0 azure-cloud-shell


【解决方案1】:

@库纳尔

如果您知道自己的存储帐户密钥,则无需“add-azureaccount”即可。

$ctx = New-AzureStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
New-AzureStorageContainer $containerName -Context $ctx

对于“add-azureaccount”的错误,你可能没有正确安装Azure Powershell。您能否重新安装最新的 Azure PowerShell 并重试:https://github.com/Azure/azure-powershell/releases/tag/v6.3.0-June2018

【讨论】:

    【解决方案2】:

    我从 azure cli 脚本创建了 100 个容器。

    它的输出将在其他命令列表中并运行此命令列表

    <code>foreach($line in [System.IO.File]::ReadLines("D:BlobNames.txt"))
    {
          $arr=$line
    foreach ($i in $arr )
    {
    $k=echo "az storage container create -n $i --account-name <Storageaccount>--account-key <accountKey> --output table" 
    Out-File -FilePath D:\commandlist -InputObject $k -Encoding ASCII -Append -NoClobber
    }
    }
    </code>  
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 2018-01-19
      • 2016-05-07
      • 1970-01-01
      • 2019-11-03
      • 2018-04-23
      相关资源
      最近更新 更多