DEV Community

Josh Duffney
Josh Duffney

Posted on

Using Azure Storage with PowerShell

Create a Resource Group

New-AzResourceGroup -Name storagePractice -Location eastus
Enter fullscreen mode Exit fullscreen mode

Create a Storage Account

New-AzStorageAccount -Name storageaccountpractice -ResourceGroupName storagePractice -Location eastus -SkuName Standard_LRS
Enter fullscreen mode Exit fullscreen mode

Get Storage Account Key Value

$key = (Get-AzStorageAccountKey -ResourceGroupName storagepractice -Name storageaccountpractice)[0].value
Enter fullscreen mode Exit fullscreen mode

Create New Storage Content

$context = New-AzStorageContext -StorageAccountName storageaccountpractice -StorageAccountKey $key
Enter fullscreen mode Exit fullscreen mode

Create a Storage Blob Container

New-AzStorageContainer -Name images -Context $context -Permission Blob
Enter fullscreen mode Exit fullscreen mode

Upload Image to Azure Storage Blob Container

Set-AzStorageBlobContent -File ./books.png -Container images -Blob 'books.png' -Context $context
Enter fullscreen mode Exit fullscreen mode

List Contents of an Azure Blob Storage Container

Get-AzStorageBlob -Container images -Context $context
Enter fullscreen mode Exit fullscreen mode

Download Contents of Azure Blob Storage Container

Get-AzStorageBlobContent -Blob "books.png" `   
-Container images `        
-Destination "books2.png" `               
-Context $context
Enter fullscreen mode Exit fullscreen mode

Remove Azure Resource Group ( Cleanup )

Remove-AzResourceGroup -Name storagePractice -Force
Enter fullscreen mode Exit fullscreen mode

Sources

Quickstart: Upload, download, and list blobs by using Azure PowerShell

Top comments (0)