Author Posts

June 14, 2018 at 11:57 am

Hi Team,
We have S3 bucket for which we need to set up retention policy of 7 days for it folder and subfolders. I wrote the below code however it gives me folders and files both. I need just files (like we use -files paramater in GCI command).

foreach ($o in $outbox)
Get-S3Object -BucketName $bucketname -AccessKey $accesskey -SecretKey $secretkey -KeyPrefix $o | where LastModified -LT (Get-Date).AddDays(-7)

How can i get only files from s3 folders.

June 14, 2018 at 12:36 pm

You'd have to see what you can filter on to determine if it is a file. The examples I see indicate the Get-S3Object returns files, like this blog:

Try adding a | Select * or Get-Member to see all of the properties that Get-S3Object returns so you can build a Where filter