I am connecting to my Azure File Share using Powershell in Azure Automation and this works fine, I can list all the files and directories. Unfortunately when I try to read the content of any of the files, the output that I get is always empty. I tried to read a csv file, a json and a text, but in all cases the Output is always empty. Is there something wrong with my code?
#Credentials for File Storage
$credentials = Get-AutomationPSCredential -Name "access_key"
# Storage account information
$storageAccountName = "xxxxx"
$storageAccountKey = $credentials.GetNetworkCredential().Password
# File share information
$shareName = "archive"
$filePath = 'test.txt'
try {
# Construct the storage context
$context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
# List all files directly under the root of the share
$files = Get-AzStorageFile -ShareName $shareName -Context $context
foreach ($file in $files) {
Write-Output "File: $($file.Name)"
}
$fileContent = Get-AzStorageFileContent -ShareName $shareName -Path $filePath -Context $context
Write-Output "File Content:"
Write-Output "$fileContent"
}
catch {
Write-Output "An error occurred: $_"
}