Introduction
In this blog, you will
see how to get all Azure Storage Accounts using PowerShell.
Prerequisites
Install Azure PowerShell Module to run the script.
PowerShell Script
Open a text file. Copy and paste the below script. Save the file as script.ps1.
- ################# Azure Blob Storage - PowerShell ####################
-
- ## Input Parameters
- $resourceGroupName="azpractice"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to get all the storage accounts
- Function GetAllStorageAccount
- {
- Write-Host -ForegroundColor Green "Retrieving the storage accounts..."
-
- ## Get the list of Storage Accounts
- $storageAccColl=Get-AzStorageAccount
- foreach($storageAcc in $storageAccColl)
- {
- write-host -ForegroundColor Yellow $storageAcc.StorageAccountName
- }
-
- Write-Host -ForegroundColor Green "Retrieving the storage accounts from specific resource group..."
-
- ## Get the list of Storage Accounts from specific resource group
- $storageAccCollRG=Get-AzStorageAccount -ResourceGroupName $resourceGroupName
- foreach($storageAcc in $storageAccCollRG)
- {
- write-host -ForegroundColor Yellow $storageAcc.StorageAccountName
- }
- }
-
- GetAllStorageAccount
-
- ## Disconnect from Azure Account
- Disconnect-AzAccount
Open PowerShell window and navigate to the location where the script file was saved. Run the following command.
.\script.ps1
Result
Summary
Thus, in this blog, you saw how to get all Azure Storage Accounts using PowerShell.