$resourceGroupName = "xbackbonektadevmc-rg"
$storageAccName = "xfssaktamc601"
$fileShareName = "imagingcenter"
$directoryPath = "Software\KTA OPMT\KofaxTotalAgility-7.11 Software\KofaxTotalAgility-7.11.0.11_OPMT"
# Define the function to list directories and files recursively
Function GetFiles
{
param (
[string]$path
)
Write-Host -ForegroundColor Green "Lists directories and files under $path.."
## Get the storage account context
$ctx = $storageAccount.Context
# Retrieve all files and folders under the file share
$filesAndFolders = Get-AZStorageFile -Context $ctx -ShareName $fileShareName -Path $path
## Loop through files and folders
foreach($item in $filesAndFolders)
{
# Check if the item is a directory
if ($item.GetType().Name -eq "AzureStorageFileDirectory")
{
Write-Host -ForegroundColor Red "Folder Name: " $item.Name
# Recursively call GetFiles function to list contents of subfolders
if ($item.Path -like "$directoryPath\*") {
GetFiles -path $item.Path
}
}
else
{
# Display file name
Write-Host -ForegroundColor Yellow "File Name: " $item.Name
}
}
}
# Start listing files and folders from the KofaxTotalAgility-7.11.0.11_OPMT folder
GetFiles -path $directoryPath
I have tried executing the script it just display the name of the folder KofaxTotalAgility-7.11.0.11_OPMT but it is not listing the files and folders inside it can you please help me adjust this script
You can use the script below to list both folder and file names using Azure PowerShell.
Script:
The script above lists all directories and files under a specified path in an Azure file share. It takes in the
resource group name,storage account name,file share name, anddirectory pathas parameters. The script retrieves the storage account context and uses theGet-AZStorageFilecmdlet to list the directories and files.Output:
Reference:
Get-AzStorageFile (Az.Storage) | Microsoft Learn