Private/ADLookups/_GetServiceAccount.ps1

function _GetServiceAccount {
    param (
        [parameter(Mandatory = $true)]
        [string]$NameToSearch,

        [parameter(Mandatory = $true)]
        [ValidateSet('*Search', '*Search*', 'Search*')]
        [string]$SearchStyle
    )

    switch ($SearchStyle) {
        '*Search' {
            $Query = "*$NameToSearch"
        }
        '*Search*' {
            $Query = "*$NameToSearch*"
        }
        'Search*' {
            $Query = "$NameToSearch*"
        }
    }

    if ($null -eq $AllServiceAccounts) {
        Return "Go to the File menu and click 'Update Object Cache'."
    }
    else {
        $ServiceAccount = @()
        $ServiceAccount += $AllServiceAccounts | Where-Object SamAccountName -Like $Query
        $ServiceAccount += $AllServiceAccounts | Where-Object DistinguishedName -Like $Query
        $ServiceAccount += $AllServiceAccounts | Where-Object Name -Like $Query
        Return $ServiceAccount | Select-Object -Unique -First 20
    }
}