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.
Successfully complete this lab by achieving the following learning objectives:
- Log in to the Linux VM
Open a new terminal.
Copy the public IP address provided with this hands-on lab.
Log in via SSH:
Once logged in, start the PowerShell prompt:
- Install the Az Module and Connect to Azure
Install the module:
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Yto continue installing from the PowerShell gallery.
From the PowerShell prompt, connect to Azure:
https://microsoft.com/deviceloginand enter the code provided in the terminal.
Enter the username and password provided with this hands-on lab.
- Create the Storage Account and Container
Create the variable
$locationand set it to
Create the variable
$resourceGroupand assign it to the resource group given with the lab (
$resourceGroup = "<RESOURCE_GROUP_WITH_THE_LAB>").
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
Set the storage context (a reference to the correct storage account):
$ctx = $storageAccount.Context
Create the storage container:
$containerName = "images"
New-AzStorageContainer -Name $containerName -Context $ctx -Permission blob
- Copy the File into the Storage Container
Download the file:
Transfer the file to the newly created storage container:
Set-AzStorageBlobContent -File "./badge-full.png" ` -Container $containerName ` -Blob "badge-full.png" ` -Context $ctx