Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Created June 9, 2021 23:49
Show Gist options
  • Save krymtkts/31a4a9399901b2996d37cd1f2ed2039f to your computer and use it in GitHub Desktop.
Save krymtkts/31a4a9399901b2996d37cd1f2ed2039f to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$BucketName,
[Parameter()]
[string]
$Prefix,
[Parameter(Mandatory = $true)]
[ValidateRange("NonNegative")]
[int]
$Level
)
$params = @{
"BucketName" = "$BucketName";
}
if ($Prefix -ne "") {
$params["Prefix"] = $Prefix
}
Get-S3Object @params | ForEach-Object -Process { try { $_.Key.Split('/')[$Level] } catch {} } | Group-Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment