Public/Get-RemedyPerson.ps1

Function Get-RemedyPerson {
<#
.SYNOPSIS
    Returns details of a person in Remedy. This can be a customer or staff.
 
.DESCRIPTION
    Use this cmdlet to return details of one or more customers or staff as stored in Remedy.
 
.EXAMPLE
    Get-RemedyPerson -Name Wragg -Staff
 
    Returns details of the specified staff member.
#>

    [cmdletbinding(DefaultParameterSetName='ByName')]
    Param(
        # Name of the person you want to return details of.
        [Parameter(ParameterSetName=’ByName’,Mandatory=$true,Position=0)]
        [String]$Name,

        # Login ID of the person you want to return details of.
        [Parameter(ParameterSetName=’ByID’,Mandatory=$true,Position=0)]
        [Alias('ID','LoginID')]
        [String]$Login,

        # Email of the person you want to return details of.
        [Parameter(ParameterSetName=’ByEmail’,Mandatory=$true,Position=0)]
        [String]$Email,

        # Use to return only people where Support Staff = Yes.
        [Switch]$Staff,

        # Return all available fields.
        [Switch]$Full,

        # Match the string exactly.
        [Switch]$Exact,

        # An encoded string representing your Remedy Credentials as generated by the Set-RemedyApiConfig cmdlet.
        [String]$EncodedCredentials = (Get-RemedyApiConfig).Credentials,
        
        # The Remedy API URL. E.g: https://<localhost>:<port>/api
        [String]$APIURL = (Get-RemedyApiConfig).APIURL
    )

    If (-not (Test-RemedyApiConfig)) { Throw 'Remedy API Test failed. Ensure the config has been set correctly via Set-RemedyApiConfig.' }

    $Headers = @{
        Authorization = "Basic $EncodedCredentials"
    }

    If ($Exact) { $Op = '='; $Wc = '' } Else { $Op = 'LIKE'; $Wc = '%25' }

    If ($Name)  { $FilterString = "'Full Name'$Op""$Wc$Name$Wc""" }
    If ($Login) { $FilterString = "'Remedy Login ID'$Op""$Wc$Login$Wc""" }
    If ($Email) { $FilterString = "'Internet E-mail'$Op""$Wc$Email$Wc""" }

    $URL = "$APIURL/CTM:People/$FilterString"

    Try {
        $Result = Invoke-RestMethod -URI $URL -Headers $Headers -ErrorAction Stop
        
        $People = @()
        $Result.PSObject.Properties | ForEach-Object { $People += $_.Value } 

        If ($Staff) { $People = $People | Where-Object { $_.'Support Staff' -eq 'Yes' } }

        If (-not $Full){
            $People = $People | Select-Object 'Full Name','Remedy Login ID','JobTitle','Company','Internet E-mail','Support Staff','Submit Date'
        }
                
    } Catch {
        Write-Error $_
    }

    Return $People
}