2
votes

I've used the Microsoft Azure PowerShell module to create an Azure storage account and blob container inside the storage account. I've set the blob container to be publicly accessible, but now I need to list the blobs from an anonymous connection.

I'm using the Windows Management Framework Core 5.0 November 2014 Preview with the Azure PowerShell module version 0.8.12.

Here is the code that I used to create the storage account, blob container, and upload a file to the container.

### Authenticate to Microsoft Azure platform
$Username = '[email protected]';
$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

1 Answers

2
votes

You need to use the -Anonymous switch parameter for the New-StorageContext command in order to authenticate anonymously against the Azure blob storage container. After that, simply use the Get-AzureStorageBlob command like normal, to list blobs in the specified blob container.

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

Get-AzureStorageBlob