Find files or directory using PowerShell in both File Share and Blob Storage?

EnterpriseArchitect 4,996 Reputation points
2023-11-17T05:06:03.0733333+00:00

Folks,

I wonder how can I use the PowerShell script to find objects (Files or directories) in my specific Azure Storage Account called 'ArchiveRepo' under both

File Share https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-portal?tabs=azure-powershell and Blob Storage https://learn.microsoft.com/en-us/azure/storage/blobs/blob-containers-powershell ?

Thank you in advance.

Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
239 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,861 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,576 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,055 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,225 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Carlos Solís Salazar 17,536 Reputation points MVP
    2023-11-17T21:31:12.53+00:00

    Certainly! To find files or directories in both Azure File Share and Azure Blob Storage using PowerShell, you can follow these steps. Note that the process involves different cmdlets for File Shares and Blob Storage.

    Finding Objects in Azure File Share

    1. Install Azure PowerShell Module: If you haven't already, install the Azure PowerShell module using the Install-Module cmdlet:
         Install-Module -Name Az -AllowClobber -Scope CurrentUser
      
    2. Connect to Azure Account: Authenticate your Azure account with:
         Connect-AzAccount
      
    3. Retrieve the File Share: Use Get-AzStorageShare to get the file share. Replace <StorageAccountName> with your Storage Account name:
         $context = (Get-AzStorageAccount -ResourceGroupName "<ResourceGroupName>" -Name "<StorageAccountName>").Context
         $fileShare = Get-AzStorageShare -Context $context | Where-Object { $_.Name -eq "ArchiveRepo" }
      
    4. List Files and Directories: Enumerate files and directories in the file share:
         Get-AzStorageFile -Context $fileShare.Context -Share $fileShare.Name
      

    Finding Objects in Azure Blob Storage

    1. Retrieve the Storage Account Context: You need the context of your storage account:
         $context = (Get-AzStorageAccount -ResourceGroupName "<ResourceGroupName>" -Name "<StorageAccountName>").Context
      
    2. List Blobs in a Container: Assuming 'ArchiveRepo' is the name of your blob container:
         Get-AzStorageBlob -Container "ArchiveRepo" -Context $context
      

    Replace <ResourceGroupName> and <StorageAccountName> with your actual resource group name and storage account name. This script will list all files and directories in the specified file share and blobs in the blob container.

    For more detailed information on these cmdlets and their usage, you can refer to the official Azure documentation:

    Accept the answer if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    2 deleted comments

    Comments have been turned off. Learn more