Get-AzureStorageFile 未设置 LastModified 属性

Get-AzureStorageFile doesn't set LastModified property

当我尝试从 Azure 共享文件目录中获取文件时,我正在使用如下所示的 powershell 代码(类似于 docs 中的示例)

$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc" | Get-AzureStorageFile | Where-Object {$_.GetType().Name -eq "CloudFile"} 

例如,假设我们在 'doc' 文件夹下有一个子文件夹和两个文件。 上面的代码将 return 这两个文件,这是预期的。

但是LastModified 属性 保持 'null' 就像图片上显示的那样(以及其他属性)

我需要 LastModified 属性 来过滤早于特定日期的文件,以便删除它们。但是,由于此值为空,因此这是不可能的。 非常感谢任何关于如何做到这一点的想法。 执行此操作的代码应如下所示:

$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc" | Get-AzureStorageFile | Where-Object { $_.GetType().Name -eq "CloudFile" -and $currentTime -gt $_.Properties.LastModified.AddMinutes($offset)} 

请注意,如果我像这样查询一个文件,例如

$file = Get-AzureStorageFile -Share $fileShare -Path "tolearn\doc\Word2003.doc"

LastModified 属性 将被正确设置。 因此,对 Get-AzureStorageFile 方法的管道调用似乎没有将这些属性设置为文件或目录 returned.

我的方法在这里不好吗,是否有更好的方法来过滤文件以便从 Azure 文件共享中删除它们?

So, it looks like that piped call to the Get-AzureStorageFile method doesn't set these properties to files or directories returned.

我得到的结果和你一样,得不到LastModified值。

作为解决方法,我们可以使用 foreach 获取每个文件的 Properties.LastModified,如下所示:

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

要设置文件的属性,您需要调用:

$file.FetchAttributes()

这是一个简短的例子:

$files = Get-AzureStorageFile -ShareName $shareName -Context $ctx | where {$_.GetType().Name -eq "CloudFile"}
foreach($file in $files) {
    $file.FetchAttributes();
    if ($file.Properties.LastModified -ge $fromDate) {
        # Download file
        Get-AzureStorageFileContent -File $file -Destination $downloadDir
    }
}

根据以下提供的信息: Azure CloubdBlob's Properties.Length returns 0