9

我刚刚开始使用 Azure,但在使用 PowerShell cmdlet 处理我的存储帐户时遇到了问题。

我在该存储帐户中创建了一个存储帐户和一个容器。接下来,我安装了 Azure Powershell SDK 和命令让等,并导入了 publishsettings 文件。当我执行 Get-AzureSubscription 或 Get-AzureStorageAccount 命令时,它会在 PowerShell 控制台中正确显示我的订阅以及各种存储端点。

但是,如果我执行 Get-AzureStorageBlob 调用或 Set-AzureStorageBlobContent 我会收到以下错误

Get-AzureStorageBlob : Can not find your azure storage credential. Please set current storage account using
"Set-AzureSubscription" or set the "AZURE_STORAGE_CONNECTION_STRING" environment variable.

我真的在这里斗智斗勇。对此错误字符串的 Google 搜索只会显示对 Github 等代码的引用。非常感谢一些帮助。

4

3 回答 3

20

对,所以我终于设法做到了!以下是有关如何使用 PowerShell 在 Azure 中创建 blob 并在其中存储文件的总体详细信息。

http://www.nikgupta.net/2013/09/azure-blob-storage-powershell/

$context = New-AzureStorageContext -StorageAccountName FunkyStorage -StorageAccountKey {Enter your storage account key here}

Set-AzureStorageBlobContent -Blob "MyFunkyBlob" -Container FunkyContainer-File "c:\temp\1.txt" -Context $context -Force
于 2013-09-14T21:01:47.227 回答
3

您可能需要设置要使用的“当前”订阅。为此,您必须运行Select-AzureSubscription.

如果您运行Get-AzureSubscription,您将在发布设置中看到所有订阅。这些订阅之一应设置为默认值。当您滚动浏览结果列表时,您会看到IsDefault每个订阅的一个属性设置为TrueFalse。如果您使用的订阅设置为False,请运行:

Select-AzureSubscription -SubscriptionName mysub

希望这可以解决您遇到的问题。

于 2013-09-14T00:26:20.053 回答
2

仅供参考:您可以另一种方式(更快的方式)执行此操作。我在 Windows PowerShell 上构建了一种与 Azure 高度集成的 Web 语言。它被称为PowerShell Pipeworks

您可以使用 4 个 cmdlet 与 blob 进行交互:

  • 获取 Blob
  • 导入 Blob
  • 导出 Blob
  • 删除-Blob

全部采用 -StorageAccount 和 -StorageKey,以及 -StorageAccountSetting 和 -StorageKeySetting。您可以将凭据保存到磁盘(或使用 Add-SecureSetting 在 Web 应用程序中使用)。一旦任何 blob cmdlet 具有存储帐户,它将继续重复使用它。

Export-Blob 也很方便,您可以通过管道将目录传递给它,它会创建正确的内容类型,并提供 -Public,它将存储它的容器标记为公共。

这些 cmdlet 比 Azure 的要早(约 3 个月),但执行时间仍然是 3/4 左右(我相信其中很大一部分是它们对凭据的查找速度较慢),值得一试。

于 2013-09-15T20:40:32.093 回答