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