Public/Remove-GhostTag.ps1
|
function Remove-GhostTag { <# .SYNOPSIS Deletes a tag from the Ghost site. .DESCRIPTION Deletes a tag permanently and takes it off every post that has it. The posts themselves stay. This cannot be undone, which is why this function asks for confirmation; use -Confirm:$false to delete from a script. Nothing is returned. .EXAMPLE Remove-GhostTag -Id '5ddc9063c35e7700383b27e0' Deletes the tag after confirmation. .EXAMPLE Get-GhostTag -Slug 'old-news' | Remove-GhostTag -Confirm:$false Deletes the tag with the slug old-news without asking. .EXAMPLE Get-GhostTag -Include 'count.posts' | Where-Object { $_.count.posts -eq 0 } | Remove-GhostTag -WhatIf Shows which tags without posts would be deleted, without deleting them. .LINK https://docs.ghost.org/admin-api .LINK https://docs.ghost.org/content-api/tags #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] [OutputType([void])] param( # Id of the tag 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($_) } } } |