Get-Person.ps1

<#
.Synopsis
   The function returns a person by chip code.
.DESCRIPTION
   The function returns persons associated with a chip code.
.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 ChipCodeHex
    Chip code in hexadecimal format.
.EXAMPLE
   Get-Person -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 -ChipCodeHex "14AB756"
   Command retrives a person with specified chip number with authentication via AccessKey
.EXAMPLE
   Get-Person -URL https://intranet.company.com/webtime12/api -Token $MyToken -ChipCodeHex "14AB756"
   Command retrives a person with specified chip number with authentication via Token.
#>

function Get-Person {
    [CmdletBinding(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)]
        [switch]$ChipCodeHex
    )

    Process {

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

       $url = $url + "/Persons"

       $Body = @{
            ChipCodeHex = $ChipCodeHex;

       }
       $json = $body | ConvertTo-Json
       Write-Verbose -Message "Send request to API endpoint $URL with access key $Token."
       $person = Invoke-RestMethod -Method Post -Uri $url -Headers @{ Authorization = $Token } -Body $json -ContentType 'application/json'

       Write-Verbose -Message "Return object Person."
       Write-Output $person
    }
}