Get-OrgCenter.ps1

<#
.Synopsis
   The function returns list of all organizational centers.
.DESCRIPTION
   The function returns list of all organizational centers.
.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 OrgCenterID
    Database ID code of organization center.
.PARAMETER IncludeChildern
    If parameter is used function returns specified organization center and all child organization centers.
.EXAMPLE
   Get-OrgCenter -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 -OrgCenterID "3"
   Command retrives specified organization center with authentication via AccessKey
.EXAMPLE
   Get-OrgCenter -URL https://intranet.company.com/webtime12/api -Token $MyToken -OrgCenterID "3" -IncludeChildern
   Command retrives specified organization center and child organization centers with authentication via Token.
#>

function Get-OrgCenter {
    [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 = $false)]
        [string]$OrgCenterId,
        [Parameter(Mandatory = $false)]
        [switch]$IncludeChildren
    )

    Process {

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

       $url = $url + "/OrgCenters"

       $Body = @{
            orgcenterid = $OrgCenterId;
            includechildren = $IncludeChildren.IsPresent
       }

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

       Write-Verbose -Message "Return object Org Center."
       Write-Output $orgcenter

    }
}