Remove-Pass.ps1

<#
.Synopsis
   Remove a pass from attendance database
.DESCRIPTION
   The function delete a pass of the specified ordinal number from attendance database. The pass will not be permanently deleted, but will be move to the inactive state.
.PARAMETER URL
    Server API url.
.PARAMETER Token
    Authentication token for accessing API data. If you use the token for authentication, don't enter access key.
.PARAMETER AccessKey
    The AccessKey to get an authentication token for accessing API data. If you use the access key to get authentication token, don't enter token.
.PARAMETER Ordinal
    Date and time of the new pass. If not specified, the current date will be used.
    .PARAMETER PersonCode
    Person's personal identification code.
.PARAMETER PersonID
    Person's database identification id.
.EXAMPLE
   Remove-Pass -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 -PersonCode 1045 -Ordinal 34562
   This command delete the pass of the specified Ordinal number and PersonCode from attendance database.

#>

function Remove-Pass {
    [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName='AccessKey')]
    param(
        [Parameter(Mandatory = $true)]
        [string]$URL,
        [Parameter(Mandatory = $true,ParameterSetName='Token')]
        [string]$Token,
        [Parameter(Mandatory = $true,ParameterSetName='AccessKey')]
        [string]$AccessKey,
        [Parameter(Mandatory = $true)]
        [string]$Ordinal,
        [Parameter(Mandatory = $false)]
        [string]$PersonCode,
        [Parameter(Mandatory = $false)]
        [string]$PersonID
)

   Process {

      if ($PSCmdlet.ParameterSetName -eq 'AccessKey') {
         if ($pscmdlet.ShouldProcess("$URL", "Get Token")){
            $SchemeToken = Get-Token -URL $URL -AccessKey $AccessKey
            $Token = $SchemeToken.Scheme + " " + $SchemeToken.Token
         }
      }

      $URL = $URL + "/Pass"

      $Body = @{
         ordinal = $Ordinal;
         personcode = $PersonCode;
         personid = $PersonID;
      }

      $json = $body | ConvertTo-Json

      Write-Verbose -Message "Send request to API endpoint $URL with access key $Token."

      if ($pscmdlet.ShouldProcess("$URL", "Delete Pass")){
         $resp = Invoke-RestMethod -Method Delete -Uri $url -Headers @{ Authorization = $Token } -Body $json -ContentType 'application/json'
         $resp

      Write-Verbose -Message "Returned response object."
      Write-Verbose -Message $resp
      }
   }
}