Public/Person/Get-PopuliPerson.ps1

function Get-PopuliPerson
{
    [alias("Get-PopuliStudent")]

    [CmdletBinding(DefaultParametersetName = 'PersonId', PositionalBinding = $true)]
    param
    (
        [Parameter(ParameterSetName = 'PersonId', Mandatory = $true, Position = 1)][string]$PersonId,
        [Parameter(ParameterSetName = 'StudentId', Mandatory = $true)][string]$StudentId,
        [Parameter(Mandatory = $false)][ValidateLength(200, 999)][string]$PopuliToken = $env:PopuliToken,
        [Parameter(Mandatory = $false)][ValidatePattern('^(?i)https:\/\/\S+\.populiweb\.com\/?$')][string]$BaseUrl = $env:PopuliBaseUrl,
        [Parameter(Mandatory = $false)][bool]$LogResult = $true
    )


    try
    {

        if ($BaseUrl -match '\/$')
        {
            $BaseUrl = $BaseUrl -replace '\/$'
        }

        $header = @{
            Authorization = $PopuliToken
        }

        $body = @{
            task = 'getPerson'
        }

        if ($PSBoundParameters.Keys -contains 'PersonId')
        {
            $body += @{person_id = $PersonId }
        }
        elseif ($PSBoundParameters.Keys -contains 'StudentId')
        {
            $body += @{student_id = $StudentId }
        }
        else 
        {
            throw "-PersonId or -StudentId must be specified"
        }

        $response = Invoke-RestMethod -Uri "$BaseUrl/api/" -Method POST -ContentType 'application/x-www-form-urlencoded' -Body $body -Headers $header

        $person = $response.response

        if ($LogResult)
        {
            Write-Log "Returning person with Id ""$PersonId$StudentId"". Returned user: $($person.first) $($person.last) ($($person.username))" -PersonId $PersonId
        }
        

        return $person
    }
    catch
    {
        if ($LogResult)
        {
            Write-Log "Error getting person with Id ""$PersonId$StudentId""" -LogType: error -ErrorObject $_ -PersonId $PersonId
        }

        Write-Error $_

        return $null
    }


}