public/Invoke-FacebookPost.ps1
function Invoke-FacebookPost { [CmdletBinding()] param( [Parameter(Mandatory=$false)] [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 { # wait 5 seconds before next post Start-Sleep -Seconds 5 # Photos endpoint $Uri = "https://graph.facebook.com/v23.0/$PageId/feed" $Form = @{ access_token = $Token message = $Message } if ($($PSBoundParameters.ContainsKey('Link'))) { $Form.Add('link',$Link) } # if # Get the response $Response = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form -ErrorAction Stop # Return response return $response } catch { throw "$($MyInvocation.MyCommand.Name): $_.Exception.Message" } # trycatch } # process } # function |