How to list out directories and files from Azure File Share PowerShell

In this Azure PowerShell article, we will discuss the quick PowerShell script to list down directories and files from Azure File Share.

How to list out directories and files from Azure File Share PowerShell

Follow the below steps.

  1. First, make sure to install Azure PowerShell on your machine.
  2. Right-click on Windows PowerShell ISE –> Select the “Run as administrator” option.
  3. Copy and paste the below script and change the name of your Resource Group, storage account,
$myrsgName="DEMORG2"  
$mystrgActName="demorg2913f"  
$myShareName="demotstestb4c6"  
  
 
Connect-AzAccount   
 
## This function will lists all the directories and files  
Function GetDirectoriesAndFiles  
{  
    Write-Host  "Please wait you will get the lists of directories and files soon."    
    ## Getting the the strg context  
    $mystrgctx=(Get-AzStorageAccount -ResourceGroupName $myrsgName -Name $mystrgActName).Context  
    $mydirectories=Get-AZStorageFile -Context $mystrgctx -ShareName $myShareName  
    
    foreach($mydirectory in $mydirectories)  
    {  
        write-host " My Directory Name: " $mydirectory.Name  
        $myfiles=Get-AZStorageFile -Context $mystrgctx -ShareName $myShareName -Path $mydirectory.Name | Get-AZStorageFile   
        foreach ($myfile in $myfiles)  
        {  
            write-host $myfile.Name  
        }  
    }  
}  
  
GetDirectoriesAndFiles    
 
## Done Done !! Disconnecting your Azure Account  
Disconnect-AzAccount   

3. Now run the above script, After executing the above script, I can able to list out directories and files from Azure File Share successfully and I got the below-expected output.

Please wait you will get the lists of directories and files soon.
 My Directory Name:  data
Functions
monaco
 My Directory Name:  LogFiles
Application
Monaco
eventlog.xml
 My Directory Name:  site
Diagnostics
wwwroot
Account                   SubscriptionName         TenantId                           
-------                   ----------------         --------                           
fewlines4biju@hotmail.com Visual Studio Enterprise 5d9d690a-0310-474d-ae8b-42df2d54...

Id                    : fewlines4biju@hotmail.com
Type                  : User
Tenants               : {5d9d690a-0310-474d-ae8b-45th2d549228, 
                        1c93a0aa-e46f-4d02-9eea-bb1efbbe8aaf}
AccessToken           : 
Credential            : 
TenantMap             : {}
CertificateThumbprint : 
ExtendedProperties    : {[HomeAccountId, 00000000-0000-0000-0f7b-0c5e09af0dfd.9188040d
                        -6c67-4c5b-b112-36a304b66dad], [Subscriptions, 
                        1cdf4300-dee5-4518-8c8c-feaa72a5ghd1], [Tenants, 5d9d690a-0310
                        -474d-ae8b-42df2d549228,1c93a0hh-e46f-4d02-9hha-bb1efbbe5kkf]}

You can see the same output in the below screenshot

How to list out directories and files from Azure File Share PowerShell

You may also like following the below articles.

Conclusion

Well, in this article, we discussed the quick PowerShell script to list out directories and files from Azure File Share PowerShell. Thanks for reading this article !!!