Get-PersonOrg.ps1
<# .Synopsis The function returns list of persons assigned to an organizational center. .DESCRIPTION The function returns list of persons assigned to an organizational center. .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, from which persons return. .PARAMETER ActiveOnly Function returns active and valid persons only. .PARAMETER ValidOnly Function returns valid persons only. .PARAMETER Date Date to determine the person's validity. If not specified, the current date will be used. .PARAMETER IncludeChildern If parameter is used function returns persons from specified organization center and all child organization centers. .EXAMPLE Get-PersonOrg -URL https://intranet.company.com/webtime12/api -AccessKey 56879065 -OrgCenterID "3" -ActiveOnly Command retrives active persons from specified organization center with authentication via AccessKey .EXAMPLE Get-PersonOrg -URL https://intranet.company.com/webtime12/api -Token $MyToken -OrgCenterID "3" -IncludeChildern Command retrives all persons from specified organization center and child organization centers with authentication via Token. #> function Get-PersonOrg { [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)] [switch]$ActiveOnly, [Parameter(Mandatory = $false)] [switch]$ValidOnly, [Parameter(Mandatory = $false)] [string]$Date = $(Get-Date -Format yyyy-MM-ddTHH:mm:ss.msZ), [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 + "/PersonsOrg" $Body = @{ activeonly = $ActiveOnly.IsPresent; validonly = $ValidOnly.IsPresent; date = $Date; orgcenterid = $orgcenterid; includechildren = $includechildren.IsPresent } $json = $body | ConvertTo-Json Write-Verbose -Message "Send request to API endpoint $URL with access key $Token." $personorg = Invoke-RestMethod -Method Post -Uri $url -Headers @{ Authorization = $Token } -Body $json -ContentType 'application/json' Write-Verbose -Message "Return object Person." Write-Output $personorg } } |