Public/Remove-GhostPost.ps1
|
function Remove-GhostPost { <# .SYNOPSIS Deletes a post from the Ghost site. .DESCRIPTION Deletes a post permanently, whatever its status. Ghost has no recycle bin, which is why this function asks for confirmation; use -Confirm:$false to delete from a script. Nothing is returned. .EXAMPLE Remove-GhostPost -Id '5b7ada404f87d200b5b1f9c8' Deletes the post after confirmation. .EXAMPLE Get-GhostPost -Filter 'status:draft+title:~Untitled' | Remove-GhostPost -WhatIf Shows which untitled drafts would be deleted, without deleting them. .LINK https://docs.ghost.org/admin-api/posts/deleting-a-post #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] [OutputType([void])] param( # Id of the post to delete. [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [string] $Id ) begin { Test-GhostConnection $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name } process { try { $uri = New-URIString -Endpoint $resources.URI -Parameters $PSBoundParameters if ($PSCmdlet.ShouldProcess($Id, $resources.Description)) { $null = Submit-Request -Uri $uri -Method $resources.Method -Success $resources.Success } } catch { $PSCmdlet.ThrowTerminatingError($_) } } } |