Creating Azure Storage and Transferring Data Using PowerShell

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

There may be a time where you find yourself wanting to transfer data from your local workstation into an Azure Storage account. In those cases, there is a PowerShell command for that. PowerShell is a powerful tool, which helps you with a lot of administrative tasks — one of those being transferring files. In this hands-on lab, you will be tasked with using PowerShell to create a storage account and storage container, taking files that reside on a Linux VM, and transferring them to an Azure Storage container.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log in to the Linux VM
  1. Open a new terminal.

  2. Copy the public IP address provided with this hands-on lab.

  3. Log in via SSH:

    ssh cloud_user@<PUBLIC_IP_OF_THE_VM>
  4. Once logged in, start the PowerShell prompt:

    pwsh 
Install the Az Module and Connect to Azure
  1. Install the module:

    Install-Module -Name Az -AllowClobber -Scope CurrentUser
  2. Enter Y to continue installing from the PowerShell gallery.

  3. From the PowerShell prompt, connect to Azure:

    Connect-AzAccount
  4. Go to https://microsoft.com/devicelogin and enter the code provided in the terminal.

  5. Enter the username and password provided with this hands-on lab.

Create the Storage Account and Container
  1. Create the variable $location and set it to westus.

  2. Create the variable $resourceGroup and assign it to the resource group given with the lab ($resourceGroup = "<RESOURCE_GROUP_WITH_THE_LAB>").

  3. Create the storage account, replacing <UNIQUE_STORAGE_ACCOUNT_NAME> with a globally unique name:

    $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroup `
      -Name "<UNIQUE_STORAGE_ACCOUNT_NAME>" `
      -SkuName Standard_LRS `
      -Location $location
  4. Set the storage context (a reference to the correct storage account):

    $ctx = $storageAccount.Context
  5. Create the storage container:

    $containerName = "images"
    New-AzStorageContainer -Name $containerName -Context $ctx -Permission blob
Copy the File into the Storage Container
  1. Download the file:

    wget http://ww1.prweb.com/prfiles/2019/12/16/16790924/badge-full.png
  2. Transfer the file to the newly created storage container:

    Set-AzStorageBlobContent -File "./badge-full.png" `
      -Container $containerName `
      -Blob "badge-full.png" `
      -Context $ctx 

Additional Resources

In this hands-on lab, you have been given a Linux VM to log in to. From this VM, you must complete all tasks. The objective is to get the PNG file, located in the cloud_user's home folder, into the storage container. You must first create a new Azure Storage account and storage container. Then, you must perform the correct PowerShell commands to transfer the file from your location workstation to the storage container.

To consider this hands-on lab complete, please complete the following:

  • Log in to the VM with the credentials provided and start PowerShell.
  • Install the Az module and log in to Azure with the credentials provided.
  • Create a new Azure Storage account.
  • Create a new Azure storage container within that storage account.
  • Download the PNG file to your local workstation (wget http://ww1.prweb.com/prfiles/2019/12/16/16790924/badge-full.png).
  • Transfer the file into the previously created storage container.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?