public/Invoke-FacebookPost.ps1
function Invoke-FacebookPost { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Link, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$PageId, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Token, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Message ) process{ $ErrorActionPreference = 'Stop' try { Start-Sleep -Seconds 10 # Photos endpoint $Uri = "https://graph.facebook.com/v22.0/$PageId/feed" $Form = @{ access_token = $Token message = $Message link = $Link } $Response = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form -ErrorAction Stop return $response } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |