Get-AzStorageAccount

Get Storage Accounts Azure PowerShell

This article will discuss how to get lists of storage accounts using the Get-AzStorageAccount PowerShell command and the syntax of the Get-AzStorageAccount PowerShell command with examples.

Get-AzStorageAccount

Get-AzStorageAccount is an excellent cmdlet that can help you retrieve the storage accounts under a specific Resource Group or 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

Examples

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

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

Once I executed the above cmdlet, I got the below-expected 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 Demo12346 Resource Group.

Get-AzStorageAccount -ResourceGroupName "Demo12346"

Once executed, I got the below-expected output

StorageAccountName ResourceGroupName PrimaryLocation SkuName        Kind      AccessTier CreationTime        ProvisioningState EnableHttpsTrafficOnly LargeFileShares
------------------ ----------------- --------------- -------        ----      ---------- ------------        ----------------- ---------------------- ---------------
newstrgact         Demo12346         eastus          Standard_RAGRS StorageV2 Hot        14-09-2023 09:31:20 Succeeded         True                                  

You check out the same output in the screenshot below

get azstorageaccount

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

Get-AzStorageAccount

Once executed, I got the below-expected 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

You can see the complete output in the screenshot below

powershell get-azstorageaccount

If you want to run a Powershell script to get Azure storage account details under your subscription or a specific Resource Group, you can utilize the Powershell script below.

## 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 I executed the above PowerShell script, I got the below output as expected.

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 powershell

You may also like following the articles below

Wrapping Up

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