In this article by John Chapman and Aman Dhally, authors of the book, Automating Microsoft Azure with PowerShell, you will see that Microsoft Azure offers a variety of different services to store and retrieve data in the cloud. This includes File and Blob storage. Within Azure, each of these types of data is contained within an Azure storage account. While Azure SQL databases are also storage mechanisms, they are not part of an Azure storage account.
(For more resources related to this topic, see here.)
In a Microsoft Azure storage account, both the Azure File storage service and the Azure Blob storage service can be used to store files. Deciding which service to use depends on the purpose of the content and who will use the content. To break down the differences and similarities between these two services, we will cover the features, structure, and common uses for each service.
Azure File storage provides shared storage using the Server Message Block (SMB) protocol. This allows clients, such as Windows Explorer, to connect and browse the File storage (such as a typical network file share). In a Windows file share, clients can add directory structures and files to the share. Similar to file shares, Azure File storage is typically used within an organization and not with users outside the organization.
Azure File shares can only be mounted in Windows Explorer as a drive within virtual machines running in Azure. They cannot be mounted from computers outside of Azure.
A few common uses of Azure File storage include:
A blob refers to a binary large object, which might not be an actual file. The Azure Blob storage service is used to store large amounts of unstructured data. This data can be accessed via HTTP or HTTPS, making it particularly useful to share large amounts of data publicly. Within an Azure storage account, blobs are stored within containers. Each container can be public or private, but it does not offer any directory structure as the File storage service does.
A few common uses of Azure Blob storage include:
Managing services provided by Microsoft Azure storage accounts require two pieces of information: the storage account name and an access key. While we can obtain this information from the Microsoft Azure web portal, we will do so with PowerShell.
Azure storage accounts have a primary and a secondary access key. If one of the access key is compromised, it can be regenerated without affecting the other.
To obtain the Azure storage account keys, we will use the following steps:
PS C:> $accountKey = Get-AzureStorageKey -
StorageAccountName psautomation
PS C:> $key = $accountKey.Primary
As mentioned in the Azure File storage versus Azure Blob storage section, Azure File services act much like typical network files shares. To demonstrate Azure File services, we will first create a file share. After this, we will create a directory, upload a file, and list the files in a directory.
To complete Azure File storage tasks, we will use the following steps:
PS C:> $context = New-AzureStorageContext psautomation $key
PS C:> $share = New-AzureStorageShare psautomationshare –Context $context
PS C:> New-AzureStorageDirectory –Share $share –Path TextFiles
PS C:> Set-Content C:FilesMyFile.txt –Value "Hello"
PS C:> Set-AzureStorageFileContent –Share $share –Source C:
FilesMyFile.txt –Path TextFiles
As mentioned in the Azure File storage versus Azure Blob storage section, Azure Blob storage can be used to store any unstructured data, including file content. Blobs are stored within containers, whereas permissions are set at the container level. The permission levels that can be assigned to a container are shown in the following table:
Permission level | Access provided |
Container | This provides anonymous read access to the container and all blobs in the container. In addition, it allows anonymous users to list the blobs in the container. |
Blob | This provides anonymous read access to blobs within the container. Anonymous users cannot list all of the blobs in the container. |
Off | This does not provide anonymous access. It is only accessible with the Azure storage account keys. |
To illustrate Azure Blob storage, we will use the following steps to create a public container, upload a file, and access the file from a web browser:
PS C:> $context = New-AzureStorageContext psautomation $key
PS C:> New-AzureStorageContainer –Name textfiles –Context $context –Permission Container
PS C:> Set-Content C:FilesMyFile.txt –Value "Hello"
PS C:> Set-AzureStorageBlobContent –File C:FilesMyFile.txt
–Blob "MyFile.txt" –Container textfiles –Context $context
In this article, you learned about Microsoft Azure storage accounts and how to interact with the storage account services with PowerShell. This included the Azure File storage and Azure Blob storage.
Further resources on this subject:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…