Public/SDK Wrappers/S3/Get-VSS3ObjectList.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Get-VSS3ObjectList {
    <#
    .SYNOPSIS
    Gets the objects from a specific S3 bucket
    
    .PARAMETER BucketName
    The name of the bucket containing the object.
    
    .PARAMETER Prefix
    Limits the response to keys that begin with the specified prefix.
    
    .PARAMETER StartAfter
    StartAfter is where you want Amazon S3 to start listing from. Amazon S3 starts listing after this specified key. StartAfter can be any key in the bucket.
    
    .PARAMETER MaxKeys
    Sets the maximum number of keys returned in the response. The response might contain fewer keys but will never contain more.
    
    .PARAMETER ProfileName
    The name of the configuration profile to deploy the stack with. Defaults to $env:AWS_PROFILE, if set.
    
    .FUNCTIONALITY
    Vaporshell
    #>

    [cmdletbinding()]
    Param
    (
        [parameter(Mandatory = $true,Position = 0)]
        [String]
        $BucketName,
        [parameter(Mandatory = $false)]
        [String]
        $Prefix,
        [parameter(Mandatory = $false)]
        [String]
        $StartAfter,
        [parameter(Mandatory = $false)]
        [System.Int32]
        $MaxKeys,
        [parameter(Mandatory = $false)]
        [String]
        $ProfileName = $env:AWS_PROFILE
    )
    Process {
        $method = "ListObjectsV2"
        $expand = "S3Objects"
        $requestType = "Amazon.S3.Model.$($method)Request"
        $request = New-Object $requestType
        foreach ($key in $PSBoundParameters.Keys) {
            if ($request.PSObject.Properties.Name -contains $key) {
                $request.$key = $PSBoundParameters[$key]
            }
        }
        $request.FetchOwner = $true
        $results = ProcessRequest $PSCmdlet.ParameterSetName $ProfileName $method $request $expand
        if (!$results) {
            return
        }
        elseif ($results -is 'System.Management.Automation.ErrorRecord') {
            $PSCmdlet.ThrowTerminatingError($results)
        }
        elseif ($results) {
            return $results | Select-Object *,@{N="OwnerDisplayName";E={$_.Owner.DisplayName}} -ExcludeProperty Owner
        }
    }
}