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 { $Url = "https://$BucketName.s3.eu-west-1.amazonaws.com" $Response = Invoke-WebRequest -Uri $Url [xml]$xml = $Response.Content if ($Type -eq 'story') { # Get the fixture artifacts $RemoteArtifacts = $xml.ListBucketResult.Contents ` | Where-Object {$_.Key -like "instagram/story/$Content*"} ` | Select-Object -ExpandProperty Key } if ($Type -eq 'post') { # Get the fixture artifacts $RemoteArtifacts = $xml.ListBucketResult.Contents ` | Where-Object {$_.Key -like "instagram/$Content*"} ` | Select-Object -ExpandProperty Key } # if $PSObjects =@() $RemoteArtifacts | ForEach-Object -Process { $FileName = $_.Split('/')[-1] $PSObject = [PSCustomObject]@{ Name = $FileName } $PSObjects += $PSObject } # foreach-object # Exclude files with special characters $FixtureArtifacts = $PSObjects | Where-Object {$_.Name -match "^[\x00-\x7F]+$"} if ($($FixtureArtifacts.Count) -le $($PSObjects.Count)) { Write-Warning -Message 'Files have special characters.' } # if return $FixtureArtifacts } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # try catch } # process } # function |