When trying to get files out of an Azure share file directory I'm using powershell code like below (similar to the example from the docs)
$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc" | Get-AzureStorageFile | Where-Object {$_.GetType().Name -eq "CloudFile"}
For example, lets assume we have one child folder and two files under the 'doc' folder. The code from above will return these two files, which is expected.
HoweverLastModified property remains 'null' like it is shown on the picture (as well as other properties)
I need LastModified property in order to filter files that are older than certain date in order to delete them. But, since this value is null, this is not possible. Any idea on how to do this is very much appreciated. Code to do that should look like this:
$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc" | Get-AzureStorageFile | Where-Object { $_.GetType().Name -eq "CloudFile" -and $currentTime -gt $_.Properties.LastModified.AddMinutes($offset)}
Please note, if I query for one file like this, for example
$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc\Word2003.doc"
LastModified property would be properly set. So, it looks like that piped call to the Get-AzureStorageFile method doesn't set these properties to files or directories returned.
Is my approach bad here, is there a better way to filter files in order to delete them from Azure file share?
So, it looks like that piped call to the Get-AzureStorageFile method doesn't set these properties to files or directories returned.
I get the same result as you, can't get LastModified
vaule.
As a workaround, we can use foreach
to get every file's Properties.LastModified
, like this:
PS C:\Users\jason> $file = Get-AzureStorageFile -Share $share -Path "jason"
PS C:\Users\jason> $c = $file | Get-AzureStorageFile
PS C:\Users\jason> $list = $c.name
PS C:\Users\jason> $list
04.PNG
08.PNG
test3
test4
PS C:\Users\jason> foreach($a in $list){$path = 'jason/'+$a ; $b = Get-AzureStorageFile -ShareName jasonshare1 -Path $path -Context $ctx; $b.Properties.LastModified }
DateTime : 11/22/2017 2:31:13 AM
UtcDateTime : 11/22/2017 2:31:13 AM
LocalDateTime : 11/22/2017 10:31:13 AM
Date : 11/22/2017 12:00:00 AM
Day : 22
DayOfWeek : Wednesday
DayOfYear : 326
Hour : 2
Millisecond : 0
Minute : 31
Month : 11
Offset : 00:00:00
Second : 13
Ticks : 636469146730000000
UtcTicks : 636469146730000000
TimeOfDay : 02:31:13
Year : 2017
DateTime : 11/22/2017 2:31:14 AM