Get-Account.ps1
<# .Synopsis The function returns list of attendance accounts .DESCRIPTION The function returns a list of all attendance accounts that are defined in the attendance system, including export parameters. .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. .EXAMPLE Get-Account -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 This command retrieves the list of attendance accounts with authentication via AccessKey .EXAMPLE Get-Account -URL https://intranet.company.com/webtime12/api -Token $MyToken This command retrieves the list of attendance accounts with authentication via Token #> function Get-Account { [CmdletBinding(DefaultParameterSetName='AccessKey')] param( [Parameter(Mandatory = $true)] [string]$URL, [Parameter(Mandatory = $false,ParameterSetName='Token')] [string]$Token, [Parameter(Mandatory = $true,ParameterSetName='AccessKey')] [string]$AccessKey ) Process { if ($PSCmdlet.ParameterSetName -eq 'AccessKey') { $SchemeToken = Get-Token -URL $URL -AccessKey $AccessKey $Token = $SchemeToken.Scheme + " " + $SchemeToken.Token } $url = $url + "/CodeLists/Accounts" $Body = @{} $json = $body | ConvertTo-Json Write-Verbose -Message "Send request to API endpoint $URL with access key $Token." $Account = Invoke-RestMethod -Method Post -Uri $url -Headers @{ Authorization = $Token } -Body $json -ContentType 'application/json' Write-Verbose -Message "Return object Absences." $($Account) } } |