Create Blob storage, upload files and list the files in AZURE PS

The PS script will create Blob storage, upload files and list the files in AZURE PS
Steps to execute the script:

1. Copy this script in your PC’s local drive:

# Connect Azure account
Connect-AzureRmAccount
# All Variables
$location = “southindia”
$resourceGroup = “blobtestmanu”
$storageGroupName = “blobstoragemanu”
$containerName = “manublobcontainer”
$FileName1 = “C:\Users\admin\Desktop\Azure\maxresdefault.jpg”
$FileName2 =”C:\Users\admin\Desktop\Azure\tasks.txt”
$Blobname1 = “maxresdefault.jpg”
$Blobname2 = “Tasks.txt”

# Create new Resource Group
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
# Create new blob storage account
$storageAccount = New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -Name $storageGroupName -Location $location -SkuName Standard_LRS
$ctx = $storageAccount.Context
# Create new container
new-azurestoragecontainer -Name $containerName -Context $ctx -Permission blob
# upload a file
set-azurestorageblobcontent -File $FileName1 -Container $containerName -Blob $Blobname1 -Context $ctx
# upload another file
set-azurestorageblobcontent -File $Blobname1 -Container $containerName -Blob $Blobname2 -Context $ctx
# List blobs
get-azurestorageblob -Container $ContainerName -Context $ctx | select Name

2. Connect Azure PS and make sure that you have all necessary PS libraries are imported to your local computer

3. Open the script and edit the # All Variables section of the script as follows, as per your convenience. I have provided some sample names already

$location = “southindia”
$resourceGroup = “blobtestmanu”
$storageGroupName = “blobstoragemanu”
$containerName = “manublobcontainer”
$FileName1 = “C:\Users\admin\Desktop\Azure\maxresdefault.jpg”
$FileName2 =”C:\Users\admin\Desktop\Azure\tasks.txt”
$Blobname1 = “maxresdefault.jpg”$Blobname2 = “Tasks.txt”

4. Save the changes and start running the script in PS

5. At first, you will be prompted to enter your azure credentials

6. Once the correct credentials are given, the script will continue without any user intervention and finally, you can see the files’s names listed at the PS prompt

7. Quickly verify in the prortal also for the new blob created

Be the first to comment

Leave a Reply

Your email address will not be published.


*