Created
June 26, 2015 15:14
-
-
Save Sam-Martin/d159522571b5e6690816 to your computer and use it in GitHub Desktop.
Get-S3FolderLastModified
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-S3FolderLastModified { | |
param( | |
[parameter(mandatory=$true)] | |
[string]$folder, | |
[parameter(mandatory=$true)] | |
[string]$bucket, | |
[parameter(mandatory=$true)] | |
[string]$region | |
) | |
$objects = Get-S3Object -BucketName $bucket -Region $region -KeyPrefix $folder | |
$folders = $objects | %{(Split-Path $_.key) -replace '\\','/'} | select -Unique | |
$folders | %{ | |
$folder = $_ | |
$objectsInThisFolder = $objects | ?{$_.key -match "$( [Regex]::Escape($folder))\/[^\/]*$"} | |
$MostRecentObject = $objectsInThisFolder | Sort-Object LastModified | select -last 1 | |
New-Object psobject -Property @{Folder=$folder;"LastModified"=$MostRecentObject.LastModified} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment