Search code examples
azurepowershellazure-files

Listing files from azure file storage that are 10 days old using shell script


$context=New-AzureStorageContext <AccountName> <AccountKey>
$isOldDate = [DateTime]::UtcNow.AddDays(-10)
Get-AzureStorageFile -Context $context | Where-Object { 
    $_.LastModified.UtcDateTime -lt $isOldDate
}

The above code is listing all the files present in a fileshare instead of listing the files that are 10 days old. Need help


Solution

  • Try this:

    $files = Get-AzureStorageFile -Context $context 
    foreach ($file in $files) { $file.fetchattributesasync() }
    $files.where{ $_.properties.lastmodified -le $date }
    

    this is what works for me for files