Public/Remove-DunePermission.ps1

<#
.SYNOPSIS
Remove a permission.

.DESCRIPTION
Deletes a permission by sending a DELETE request. Accepts a permission object via pipeline or by id. ShouldProcess is observed.

.PARAMETER Permission
A `DunePermission` object to remove (pipeline input supported).

.PARAMETER Id
The GUID of the permission to remove.

.EXAMPLE
PS> Get-DuneUser -Email "john.doe@example.com" | Get-DunePermission | Remove-DunePermission
Removes all permissions of the supplied user.

.EXAMPLE
PS> Remove-DunePermission -Id $PermissionId
Removes the permission with the specified id.
#>

function Remove-DunePermission {
    [CmdletBinding(
        SupportsShouldProcess,
        DefaultParameterSetName = 'Id',
        ConfirmImpact = 'High'
    )]
    param(
        [Parameter(ValueFromPipeline, ParameterSetName = 'Object')]
        [DunePermission]$Permission,

        [Parameter(ParameterSetName = 'Id')]
        [guid]$Id
    )

    begin {}

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        if ($PSCmdlet.ParameterSetName -eq 'Id') { $Permission = Get-DunePermission -Id $Id -ErrorAction Stop }

        if ($PSCmdlet.ShouldProcess($Permission.ToString())) {
            $null = Invoke-DuneApiRequest -Uri "authorization/permissions/$($Permission.Id)" -Method DELETE -ErrorAction Stop
        }
    }

    end {}
}