Overview Of Microsoft Azure Storage - Part Two

In this article of the series, I’m going to show how we can manage our Azure Account by using Azure PowerShell ISE, by which we’ll see how we can perform different operations on storage and the same also with Azure Explorer. There are some commands that help access the Azure Account.

Windows Azure PowerShell ISE (Integrated Scripting Environment)

It is a Windows based GUI and framework from Microsoft. It has a predefined set of commands along with non-scripting language. PowerShell is a Command-line Shell which is similar to the command window, interactive editor built on .Net framework. When we are writing scripts on PowerShell, we have complete access to entire .NET framework, such as all the classes, different methods, and data types.

PowerShell ISE has Commands Add-on Pane which helps in easily creating different scripts having to type all the commands in the command line conveniently.

Along with Commands Add-on Pane, we have script pane for writing the scripts, and Command Pane. You can toggle the script and commands On and Off from the View menu. With the help of Command-Add-On Pane, you don’t need to type any command on Command Pane, just select the command whatever you want to run from Commands Add-On Pane and run it.
Azure

Commands Add-On pane has several properties to perform your commands. For example - if you want to work only with Azure Storage Account, then just select Azure.Storage from the module. Then only, the list of Azure Storage commands is shown on your screen. You can write the module name in the Name section whatever you want to work with. Let’s assume if you select Azure.Storage module and want to perform a command from the available list, just select it and click on to Insert. It will ask showing parameters - just click on Run to run a command.

Azure

Well, the PowerShell ISE is installed by default with Windows 10 when you’re installing PowerShell from SDK. In modules, select Azure.

Azure

You can see the list of Azure related commands. Here I need to add my Azure account credentials with PowerShell, just select one of the highlight command as shown in following screenshot

Azure

Click on Show Details to add parameters.

Azure

Click on insert to insert command on Command pane, and click on Run to run the command.

Azure

That will open a page for Microsoft account. Enter your credentials to add account with PowerShell ISE.

Azure

When your account will be added then PowerShell returned your Azure account Id to ensure that you’re connected.

Azure

In my Azure Account, I have only one subscription that is “Visual Studio Enterprise with MSDN”. If you want to confirm your subscription run a command

Get-AzureSubscription

Azure

If you want to read all commands then you can run a command to show a list of commands with description.

Run- Get-Command

Azure

Create a new storage account.

For creating a new Storage Account give a storage account name (lower letters) and your specific location where you want to create account.

New-AzureStorageAccount –StorageAccountName “mystoragecontainer002” –Location “East Asia”

Azure

Get your Storage Account details on PowerShell cmdlet that will return a full detail of your storage account.

Get-AzureAccount

Azure

Check onto Azure Portal to see if our new storage is created or not.

Azure

Yes it has been created, now I want to create a Container in this Account. If you write a command of creating a container, the Azure PowerShell command didn’t recognized in which Storage Account you want to create your Container. Here I have to tell Azure PowerShell which account I want to use by setting a default storage account. To perform all operations to your default storage account write  thefollowing command

Set default storage account to new storage account

Set-AzureSubscription -CurrentStorageAccountName “mystoragecontainer002” -SubscriptionName “Visual Studio Enterprise with MSDN”

Azure

Get Azure Storage Account Keys through Storage Account Name

Get-AzureStorageKey –StorageAccountName “mystoragecontainer002”

Azure

Create a Container

To create a new Container give a name (lower case) to your Container. In previous articles I’ve discussed that for accessing your data from containers you have  to change permission for anonymous read access. If you give Permission as Off to your Container then anonymous users can’t access your data. You can set Permission to Off or Blob or Container as discussed in one of the series' articles.

New-AzureStorageContainer -Name “mycontainerforazure” -Permission Off

Azure

Check onto Azure Portal the Container should be created.

Azure

Retrieve a Container by Name

If you want to retrieve a container by its name you can run the following command

Get-AzureStorageContainer –Name “mycontainerforazure”

Azure

Upload a Blob into Container

You know that every blob resides in a particular Container so I need to pass container name in which I want to upload a blob with a appropriate path of file in the following command

Set-AzureStorageBlobContent -Container “mycontainerforazure” -File “D:\downloads\lion.jpg”

In the following screenshot you can see I’ve uploaded two different blobs into the same container.

Azure

Retrieve a list of available blobs from Container

This command retrieves all the blobs that are in your Container.

Get-AzureStorageBlob -Container “mycontainerforazure”

Azure

Delete a Selected Blob from Container

To delete a blob you must know the blob name as shown in following screenshot.

Azure

Download Blobs into Local Folder

If you want to download your blobs into your local directory then you have to write couple of commands.

  1. Get a reference to a list of all blobs in a container
    $blobs=Get-AzureStorageBlob -Container "mycontainerforazure"
  1. Create the destination directory where you want to save your items.
    New-Item -Path "D:\downloads" -ItemType Directory –Force

    Azure
  1. This command will Download blobs into your local destination directory
    $blobs=Get-AzureStorageBlob -Destination "D:\downloads"

The below screenshot shows this type of confirmation because I already have the same blobs under the same folder.

Azure

Wait for a second, it retrieves all blobs which are in Container onto PowerShell cmdlets.

Azure

Unlike Blob Storage, you can perform commands against Table Storage, Queue Storage and File Storage on Azure PowerShell ISE.


Similar Articles
IotCoast2Coast
Improving the World of Tomorrow :- We offer application development and support services.