Public/Set-GhostTier.ps1

function Set-GhostTier {
    <#
    .SYNOPSIS
        Updates a tier on the Ghost site.

    .DESCRIPTION
        Changes the properties that are passed and leaves every other property of the tier as it is. Pass an
        empty string to clear the description or the welcome page, and an empty list to clear the benefits.

        A tier cannot be deleted: -Active $false archives it. Its members keep their subscription and nobody new
        can choose it. -Active $true brings it back.

        The slug and the type of a tier cannot be changed.

    .EXAMPLE
        Set-GhostTier -Id '622727ad96a190e914ab6664' -Name 'Silver' -Description 'Every post, every week.'

        Renames the tier and gives it a description.

    .EXAMPLE
        Get-GhostTier -Filter "name:'Gold'" | Set-GhostTier -MonthlyPrice 1200 -YearlyPrice 12000

        Changes the prices of the tier Gold.

    .EXAMPLE
        Set-GhostTier -Id '622727ad96a190e914ab6664' -Benefits 'Every post', 'The archive', 'A monthly call'

        Replaces the benefits of the tier.

    .EXAMPLE
        Set-GhostTier -Id '622727ad96a190e914ab6664' -Active $false

        Archives the tier.

    .LINK
        https://docs.ghost.org/admin-api/tiers/updating-a-tier
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType('Ghost.Tier')]
    param(
        # Id of the tier to update.
        [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [string] $Id,

        # Name of the tier.
        [ValidateNotNullOrEmpty()]
        [string] $Name,

        # Price for a month, in the smallest unit of the currency: 500 is 5.00.
        [ValidateRange(1, [int]::MaxValue)]
        [int] $MonthlyPrice,

        # Price for a year, in the smallest unit of the currency: 5000 is 50.00.
        [ValidateRange(1, [int]::MaxValue)]
        [int] $YearlyPrice,

        # Currency of the prices, as its ISO code of three letters, such as usd or eur.
        [ValidatePattern('^[A-Za-z]{3}$')]
        [string] $Currency,

        # Description of the tier, shown where a member chooses one.
        [string] $Description,

        # What a member gets, one line per benefit. They replace the benefits the tier has.
        [AllowEmptyCollection()]
        [string[]] $Benefits,

        # Number of days a new member can try the tier for free. 0 is no trial.
        [ValidateRange(0, [int]::MaxValue)]
        [int] $TrialDays,

        # Whether the tier is offered on the site: public, or none for a tier that only you hand out.
        [ValidateSet('public', 'none')]
        [string] $Visibility,

        # Address a member is sent to after subscribing, such as /welcome.
        [string] $WelcomePageUrl,

        # $false archives the tier, $true brings an archived tier back.
        [bool] $Active
    )

    begin {
        Test-GhostConnection
        $resources = Get-GhostAPIData -Endpoint $MyInvocation.MyCommand.Name
    }

    process {
        try {
            $uri = New-URIString -Endpoint $resources.URI -Parameters $PSBoundParameters
            $body = New-BodyString -BodyKeys $resources.Body -Parameters $PSBoundParameters -Wrapper $resources.Result
            if (-not $body) {
                throw 'Nothing to update: pass at least one property of the tier, such as -Name or -MonthlyPrice.'
            }

            if ($PSCmdlet.ShouldProcess($Id, $resources.Description)) {
                $result = Submit-Request -Uri $uri -Method $resources.Method -Body $body -Success $resources.Success
                $result = Test-ReturnFormat -Result $result -Location $resources.Result

                Set-ObjectTypeName -InputObject $result -TypeName $resources.TypeName
            }
        }
        catch {
            $PSCmdlet.ThrowTerminatingError($_)
        }
    }
}