Get-AzureStorageFile bug
When you use Get-AzureStorageFile to retrieve the list of files in a folder, it only returns the folder name.
Get-AzureStorageFile -Share $s -Path myfoldername
I asked Gaurav Mantri about it, and he looked at it and said "The cmdlet simply makes a 'Head' request to get the properties of the directory. It doesn't fetch the files."
He also said the cmdlet is making https://msdn.microsoft.com/en-us/library/azure/dn194272.aspx request instead of https://msdn.microsoft.com/en-us/library/azure/dn166980.aspx
I know this used to work; I found it in several demos that I've given on Azure Files over the past year.
Thanks, Robin
A workaround in the meantime is to pipe the command to Get-AzureStorageFile again which will then retrieve the files in the folder. Maybe this only works for some parametersets, but for example this just returns the ReportTemplates folder name:
get-azurestoragefile -sharename 'myshare' -Path '3.3.0.22/ReportTemplates'
whereas this returns the files within the ReportTemplates folder:
get-azurestoragefile -sharename 'myshare' -Path '3.3.0.22/ReportTemplates' | get-azurestoragefile
Thanks. I'll make a note of that.
My problem is that I'm writing courseware, and just wrote a hands-on lab for using PowerShell to manage Azure Files, and I don't want to put a workaround in there. I just put the right command in there, said it didn't work right now, but that they would probably fix it by the time the course was available. In the meantime, they can check the portal for the files to make sure the lab worked. The entire course is due by EOD Thursday, so my options are limited.
@robinsh The cmdlet Get-AzureStorageFile should not only be able to list files/directories under a share/directory, but also be able to get instance and attributes of a single file or a directory. The old behavior only can do list, but is pain to get a single file's instance.
With current Get-AzureStorageFile, it can get a single instance of file/directory with Path parameter and list the share/directory if Path is not specified. To list a specific directory, you can first get the directory instance and then list it: $dir = Get-AzureStorageFile -ShareName 'sharename' -Path 'dirpath' -Context $ctx Get-AzureStorageFile -Directory $dir
Feel free to reactivate the issue if the above suggestion does not address your questions.
Is this going to get fixed, or is the workaround now permanently required?
Workaround by @EmmaZhu works, however it's 2018 and still occuring for me (Azure module 5.3.0 & AzureRM module 6.8.1 ...
@bcrotty , @brendan-sherrin The comment from Emma above has explained the the behavior of Get-AzureStorageFile, it is by design currently, and we don't have plan to change it till now. Let us know if you have strong reason to change it.
Run Get-AzureStorageFile with -Path , it will directly return the Object on the path (single File or single Directory). If need list the files/sub dirs under the path, need first get the directory object on the path, then input the directory object into Get-AzureStorageFile. like:
get-azurestoragefile -sharename 'myshare' -Path '3.3.0.22/ReportTemplates' | get-azurestoragefile
I also faced this issue. I understand the reason and the workaround suggested by @blueww works, but it took me time to find it, it should be clearly documented in https://docs.microsoft.com/en-us/powershell/module/azure.storage/get-azurestoragefile?view=azurermps-6.13.0.
@Yvand Actually, you can find it in the example 2 in the link you provided.