public/Get-InstagramContent.ps1

function Get-InstagramContent {
    <#
        .EXAMPLE
            Get-InstagramContent -BucketName content-bucket -Content corners -Type post
 
        .EXAMPLE
            Get-InstagramContent -BucketName content-bucket -Content corners -Type story
 
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$BucketName,

        [Parameter(Mandatory=$true)]
        [ValidateSet('corners','goals','match','outcomes')]
        [string]$Content,

        [Parameter(Mandatory=$true)]
        [ValidateSet('post','story')]
        [string]$Type

    )
    process {

        $ErrorActionPreference = 'Stop'

        try {


            if ($Type -eq 'Story') {

                $Prefix = "instagram/story/$Content/"

            }

            if ($Type -eq 'post') {

                $Prefix = "instagram/$Content/"

            }
    
            # S3 REST API endpoint
            $Url = "https://$BucketName.s3.eu-west-1.amazonaws.com/?list-type=2&prefix=$Prefix"

            $Response = Invoke-WebRequest -Uri $Url -UseBasicParsing
            [xml]$xml = $Response.Content
            
            # Get the fixture artifacts
            $RemoteArtifacts = $xml.ListBucketResult.Contents | ForEach-Object {
                [PSCustomObject]@{
                    Key = $_.Key
                    LastModified = $_.LastModified
                    Size = $_.Size
                }
            }

            #$RemoteArtifactToProcess = $RemoteArtifacts | Where-Object {$_.Name -match "^[\x00-\x7F]+$"}
        
            #return $RemoteArtifactToProcess

            return $RemoteArtifacts

        }
        catch {

            throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch

    } # process

} # function