Remove-PasswordStatePassword.ps1

<#
.SYNOPSIS
    Deletes a password state entry.
.DESCRIPTION
    Deletes a password state entry.
.PARAMETER PasswordID
    ID value of the entry to delete. Int32 value
.PARAMETER sendtorecyclebin
    Send the password to the recyclebin or permenant delete.
.PARAMETER Reason
    A reason which can be logged for auditing of why a password was removed.
.EXAMPLE
    PS C:\> Remove-PasswordStatePassword -PasswordID 5 -sendtorecyclebin
    Returns the test user object including password.
.INPUTS
    PasswordID - ID of the Password entry (Integer)
    SendtoRecyclebin - Optionally soft delete to the reyclebin
.OUTPUTS
    Returns the Object from the API as a powershell object.
.NOTES
    Daryl Newsholme 2018
#>

function Remove-PasswordStatePassword {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute(
        'PSAvoidUsingPlainTextForPassword', '', Justification = 'Not a password just an ID'
    )]
    [CmdletBinding(SupportsShouldProcess = $true)]
    param (
        [parameter(ValueFromPipelineByPropertyName, Position = 0, Mandatory = $true)][int32]$PasswordID,
        [parameter(ValueFromPipeline, Position = 1, Mandatory = $false)][Switch]$SendToRecycleBin,
        [parameter(ValueFromPipelineByPropertyName, Position = 2, Mandatory = $false)][string]$reason
    )

    begin {
    }

    process {
        if ($reason) {
            $headerreason = @{"Reason" = "$reason"}
        }
        if ($PSCmdlet.ShouldProcess("PasswordID:$($PasswordID) Recycle:$Sendtorecyclebin")) {
            if ($SendToRecycleBin) {
                $result = Remove-PasswordStateResource -uri "/api/passwords/$($PasswordID)?MoveToRecycleBin=$sendtorecyclebin" -extraparams @{"Headers" = $headerreason}
            }
            Else {
                $result = Remove-PasswordStateResource -uri "/api/passwords/$($PasswordID)?MoveToRecycleBin=False" -extraparams @{"Headers" = $headerreason}
            }
        }
    }

    end {
        # Use select to make sure output is returned in a sensible order.
        Return $result
    }
}