public/Invoke-AutomatedSocialMediaPost.ps1
function Invoke-AutomatedSocialMediaPost { [CmdletBinding()] param( [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [string]$BucketName, [Parameter(Mandatory=$true)] [ValidateSet('corners','goals','match','outcomes')] [string]$Content, [Parameter(Mandatory=$true)] [ValidateSet('australia','europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')] [string]$Continent, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Date, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$PageId, [Parameter(Mandatory=$false)] [switch]$Post, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory=$true)] [ValidateSet('facebook','instagram')] [string]$Platform, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Token ) process{ $ErrorActionPreference = 'Stop' try { $Competions = Select-FootballCompetition -Continent $Continent $Competions | Format-Table $Competions.GetEnumerator() | ForEach-Object -Process { Write-Warning -Message "$($MyInvocation.MyCommand.Name): Processing $Platform $Content $($_.Key) $Date." $Prompt1 = Read-UserInput -Title $($MyInvocation.MyCommand.Name) -Message "Post $Content content $($_.Key) $Date." if ($Prompt1 -eq 1) { Write-Warning -Message "$($MyInvocation.MyCommand.Name): Skipping post $Content content $($_.Key) $Date." } else { if ($Platform -eq 'facebook') { $FBParams =@{ PageId = $PageId Token = $Token Competition = $($_.Key) Date = $Date Content = $Content Path = $Path } if ($Post) { $FBParams.Add('post',$true) } # if # Facebook post Invoke-AutomatedFacebookPostWithPhoto @FBParams # Facebook story Invoke-AutomatedFacebookStoryWithPhoto @FBParams } # if if ($Platform -eq 'instagram' -and $($PSBoundParameters.ContainsKey('BucketName'))) { $InstaParams =@{ PageId = $PageId Token = $Token Competition = $($_.Key) Date = $Date Content = $Content BucketName = $BucketName Path = $Path } if ($Post) { $InstaParams.Add('post',$true) } # if # Instagram post Invoke-AutomatedInstagramSingleMediaPost @InstaParams # Instagram story Invoke-AutomatedInstagramSingleMediaStoryPost @InstaParams } # if } # if } # foreach-object } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # try catch } # process } # function |