In this article, you will see how to get all Storage Accounts using PowerShell.
Install the Azure PowerShell Module:
Open Windows PowerShell window and run the below command.
Install-Module -Name Az –AllowClobber
Get All Storage Accounts:
Open a text file. Copy and paste the below script. Save the file as script.ps1.
################# Azure Blob Storage - PowerShell ####################
## Input Parameters
$resourceGroupName="psspschennairg"
## 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 Windows PowerShell window and navigate to the location where the script file was saved.
Run the following command.
.\script.ps1
Summary:
Thus in this article you saw how to get all Azure Storage Accounts using PowerShell.
Comments