Get Storage Accounts Azure PowerShell

Get Storage Accounts Azure PowerShell

In this article, we will discuss how to get lists of storage accounts using PowerShell under one specific Resource Group.

Get Storage Accounts Azure PowerShell

We will use the Get-AzStorageAccount cmdlet to retrieve the storage accounts. Let’s discuss Get-AzStorageAccount Azure PowerShell cmdlet.

Get-AzStorageAccount

Get-AzStorageAccount is an excellent cmdlet that can help you to retrieve the storage accounts under a specific Resource Group or under a specified subscription.

Syntax:

Below is the syntax to use the Get-AzStorageAccount cmdlet.

Get-AzStorageAccount -ResourceGroupName "Your resource Group Name" -Name "The name of your storage account"
Get-AzStorageAccount -ResourceGroupName "Your resource group name"
Get-AzStorageAccount

For Example, the Below cmdlet will provide the details of democt34 storage account under the Demo123 resource group.

Get-AzStorageAccount -ResourceGroupName "Demo123" -Name "democt34"

Once I have executed the above cmdlet, it will give the below output.

ResourceGroupName           : Demo123
StorageAccountName          : democt34
Id                          : /subscriptions/1cdf4300-dee5-5418-5t5t-feaa72a5cbd1/reso
                              urceGroups/Demo123/providers/Microsoft.Storage/storageAc
                              counts/democt34
Location                    : eastus
Sku                         : Microsoft.Azure.Commands.Management.Storage.Models.PSSku
Kind                        : StorageV2
Encryption                  : Microsoft.Azure.Management.Storage.Models.Encryption
AccessTier                  : Hot
CreationTime                : 2/21/2022 11:11:13 AM
CustomDomain                : 
Identity                    : 
LastGeoFailoverTime         : 
PrimaryEndpoints            : Microsoft.Azure.Management.Storage.Models.Endpoints
PrimaryLocation             : eastus
ProvisioningState           : Succeeded
SecondaryEndpoints          : Microsoft.Azure.Management.Storage.Models.Endpoints
SecondaryLocation           : westus
StatusOfPrimary             : Available
StatusOfSecondary           : Available
Tags                        : {}
EnableHttpsTrafficOnly      : True
AzureFilesIdentityBasedAuth : 
EnableHierarchicalNamespace : True
FailoverInProgress          : 
LargeFileSharesState        : 
NetworkRuleSet              : Microsoft.Azure.Commands.Management.Storage.Models.PSNet
                              workRuleSet
BlobRestoreStatus           : 
GeoReplicationStats         : 
AllowBlobPublicAccess       : 
MinimumTlsVersion           : TLS1_2
Context                     : Microsoft.WindowsAzure.Commands.Common.Storage.LazyAzure
                              StorageContext
ExtendedProperties          : {}



Or, you can execute the below cmdlet to retrieve the storage accounts under Demo123 Resource Group.

Get-AzStorageAccount -ResourceGroupName "Demo123"

Once executed I got the below output

StorageAccountName ResourceGroupName PrimaryLocation SkuName        Kind      AccessTi
                                                                              er      
------------------ ----------------- --------------- -------        ----      --------
democt34           Demo123           eastus          Standard_RAGRS StorageV2 Hot     

Or, If you want to list down all the storage accounts under your subscription, you can execute the below command no need to mention the Resource Group name or storage account name.

Get-AzStorageAccount

Once executed, I got the below output.

StorageAccountName  ResourceGroupName                PrimaryLocation SkuName        Ki
                                                                                    nd
------------------  -----------------                --------------- -------        --
democt34            Demo123                          eastus          Standard_RAGRS St
demostrgact         Demo690                          eastus          Standard_RAGRS St
csg1003bffda6faf387 cloud-shell-storage-centralindia centralindia    Standard_LRS   St

If you want to run a script to retrieve the complete list of storage accounts under your subscription or under a specific Resource Group then you can utilize the below Powershell script.

## Provide the resource group name as the input
$rsgName="Demo123"   
  
Connect-AzAccount   
 
## This function will retrieve all the storage accounts  
Function GetListOfStorageAccounts  
{  
    Write-host -ForegroundColor Magenta "Wait..Getting you the list of storage accounts ###"  
 
    ## Retrieve all the storage accounts
    $stList=Get-AzStorageAccount  
    foreach($mystrgAcc in $stList)  
    {  
        write-host -ForegroundColor Green $mystrgAcc.StorageAccountName  
    }   
  
    Write-Host -ForegroundColor Magenta "Getting you the list of storage accounts from the provided resource group ###"  
 
    ## Retrieve all the storage accounts under specified Resource Group
    $strg=Get-AzStorageAccount -ResourceGroupName $rsgName  
    foreach($mystrgAcc in $strg)  
    {  
        write-host -ForegroundColor Green $mystrgAcc.StorageAccountName  
    }  
}  
  
GetListOfStorageAccounts  
 

Disconnect-AzAccount   

Once executed the above PowerShell script, I got the below output.

Wait..Getting you the list of storage accounts ###
democt34
demostrgact
csg1003bffda6faf387
Getting you the list of storage accounts from the provided resource group ###
democt34
Account                   SubscriptionName         TenantId                           
-------                   ----------------         --------                           
xyz@hotmail.com Visual Studio Enterprise 5d9d6kj6-0310-474d-ae8b-42df2d54...

Id                    : xyz@hotmail.com
Type                  : User
Tenants               : {5d9d690a-0125-474d-ae8b-42df2d548776, 
                        1c93a0aa-e46f-4d02-9eea-bb1efbbe5aaf}
AccessToken           : 
Credential            : 
TenantMap             : {}
CertificateThumbprint : 
ExtendedProperties    : {[HomeAccountId, 00000000-0000-0000-0f7b-0c5e09af0dfd.9188040d
                        -6c67-4c5b-b112-36a304b66dad], [Subscriptions, 
                        1cdf4311-dee5-4518-9c9c-feaa72a5cbd1], [Tenants, 5d9d690a-0310
                        -474d-ae8b-42df2d549228,1c93a0cc-e46f-4d02-9eea-bb1efbbe5aaf]}

You can see it below

Get AzStorageAccount
azure powershell get storage account

You may also like following the below articles

Wrapping Up

Well, In this article, we have discussed how to get all the storage accounts using PowerShell and with the help of Get-AzStorageAccount cmdlet.