AWS S3 PS script to get files less than 7 days and delete it

This topic contains 1 reply, has 2 voices, and was last updated by  Rob Simmers 6 days, 17 hours ago.

  • Author
  • #102460

    Parth Gandhi

    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.

  • #102469

    Rob Simmers

    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

You must be logged in to reply to this topic.