public/Get-InstagramPostCount.ps1

function Get-InstagramPostCount {
    <#
        .EXAMPLE
            Get-InstagramPostCount -Date 2025-04-12 -Path C:\sportsmonk
         
    #>

    [CmdletBinding()]
    param(

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

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path

    )
    process {

        $ErrorActionPreference = 'Stop'

        try {

            [int]$DateYear = $Date.Split('-')[0]
            [int]$DateMonth = $Date.Split('-')[1]

            if ($DateMonth -lt 10) {

                $DateMonthToUse = "0$DateMonth"

            } # if

            $InstagramPosts = Get-ChildItem -Path "$Path\fixture-artifact\processed-fixtures\$DateYear\$DateMonthToUse\media" -Recurse | Where-Object {$_.Name -like '*instagram*'}
            $InstagramPostCount = 0

            foreach ($InstagramPost in $InstagramPosts) {

                $FileCreationDate = $($InstagramPost.CreationTime)
                $FormattedDate = Get-Date $FileCreationDate -Format "dd-MM-yyyy"
                $Today = Get-Date -Format dd-MM-yyyy

                if ($FormattedDate -eq $Today) {

                    $InstagramPostCount ++

                }

            } # foreach

            if ($InstagramPostCount -eq 45) {

                throw "InstagramPostCount is $InstagramPostCount on $Today. AppInstagram accounts are limited to 50 API-published posts within a rolling 24-hour period."

            }
            else {

                $Hash1 =@{
                    InstagramPostCount = $InstagramPostCount
                    Date = $Today
                }

                $Hash1

            } # if

        }
        catch {

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

        } # try catch


    } # process

} # function