匿名列出公共容器中的Azure存储blob

时间:2015-01-09 16:53:22

标签: powershell azure

我已使用Microsoft Azure PowerShell模块在存储帐户中创建Azure存储帐户和blob容器。我已将blob容器设置为可公开访问,但现在我需要从匿名连接列出blob。

我使用Azure管理模块版本0.8.12的Windows Management Framework Core 5.0 2014年11月预览。

以下是我用来创建存储帐户,blob容器以及将文件上传到容器的代码。

### Authenticate to Microsoft Azure platform
$Username = 'powershell@trevorsullivan.net';
$AzureCredential = Get-Credential -Message 'Enter your Azure password.' -UserName $Username;
Add-AzureAccount -Credential $AzureCredential;

### Select the appropriate Azure subscription
$SubscriptionName = 'Visual Studio Ultimate with MSDN';
Select-AzureSubscription -SubscriptionName $SubscriptionName;

### Create Azure Storage Account
$StorageAccountName = 'opsgility';
New-AzureStorageAccount -StorageAccountName $StorageAccountName;

### Create Azure Storage Context
$StorageKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName;
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageKey.Primary;

### Create a blob storage container with "container" level public access
$ContainerName = 'uploads';
New-AzureStorageContainer -Context $Context -Name $ContainerName -Permission Container;

### Upload a file to the blob container
Set-AzureStorageBlobContent -Context $Context -Container $ContainerName -File c:\windows\notepad.exe;

###
### How do I retrieve a list of Azure storage blobs from the container anonymously?
###

1 个答案:

答案 0 :(得分:2)

您需要使用-Anonymous命令的New-StorageContext开关参数,以便对Azure blob存储容器进行匿名身份验证。之后,只需像普通一样使用Get-AzureStorageBlob命令,在指定的blob容器中列出blob。

$AnonContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -Anonymous;
Get-AzureStorageBlob -Context $AnonContext -Container $ContainerName;

Get-AzureStorageBlob