Public/Person/Get-PopuliPerson.ps1
function Get-PopuliPerson { [alias("Get-PopuliStudent")] [CmdletBinding(DefaultParametersetName='PersonId', PositionalBinding=$true)] param ( [Parameter(ParameterSetName='PersonId', Mandatory=$true)][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 ) 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 Write-Log "Returning person with Id ""$PersonId$StudentId"". Returned user: $($person.first) $($person.last) ($($person.username))" return $person } catch { Write-Log "Error getting tags" -LogType: error -ErrorObject $_ Write-Error $_ return $null } } |