Get-AzStorageAccount with unrestricted public access as .CSV file?

EnterpriseArchitect 5,036 Reputation points
2021-06-17T06:35:09.09+00:00

How can I get the list as .CSV file of the Azure Storage Account with the open Public access or Unrestricted, and also the entire configuration like in the below screenshot?

106455-image.png

Because when I open this page: https://video2.skills-academy.com/en-us/powershell/module/az.storage/get-azstorageaccount?view=azps-6.1.0

There is no way to get the additional information like:

Secure transfer required,
Allow Blob public access,
Allow storage account key access,
Minimum TLS Version,
Blob access tier (default)

This is what I can get so far:

Get-AzStorageAccount | Select * | ogv  
Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
240 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,874 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 35,011 Reputation points Microsoft Employee
    2021-06-17T20:58:04.803+00:00

    @EnterpriseArchitect
    You can use this PowerShell script to generate a csv. I believe it includes the fields you need, but feel free to add more if needed.

     $context = Get-AzContext  
          
     $storageAccounts = Get-AzResource -ResourceType 'Microsoft.Storage/storageAccounts'   
          
     [System.Collections.ArrayList]$saUsage = New-Object -TypeName System.Collections.ArrayList  
          
      foreach ($storageAccount in $storageAccounts) {  
          
          
                 $StorageAccountDetails = [ordered]@{  
                         SubscriptionName = $context.Subscription.Name  
                         SubscrpitionID = $context.Subscription.Id  
                         StorageAccountName = $storageAccount.Name  
                         ResourceGroup = $storageAccount.ResourceGroupName  
                         Location = $storageAccount.Location  
    					 SecureTransferRequired = (Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.Name).EnableHttpsTrafficOnly  
                         BlobPublicAccess = (Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.Name).AllowBlobPublicAccess  
    					 AllowSharedKeyAccess = (Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.Name).AllowSharedKeyAccess  
    					 MinimumTLSVersion = (Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.Name).MinimumTlsVersion  
    					 AccessTier = (Get-AzStorageAccount -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.Name).AccessTier  
                         BlobSoftDelete = (Get-AzStorageBlobServiceProperty -ResourceGroupName $storageAccount.ResourceGroupName -StorageAccountName $storageAccount.Name).DeleteRetentionPolicy.Enabled  
    					   
                   }  
                  $saUsage.add((New-Object psobject -Property $StorageAccountDetails))  | Out-Null     
     }  
     $saUsage | Export-Csv -Path C:\Users\username\test.csv -NoTypeInformation  
    

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments