Public/Get-Accounts.ps1

Function Get-Accounts {
    <#
        .SYNOPSIS
        Gets a list of all associated accounts to the user found with the given search term
         
        .DESCRIPTION
        Provide a search term, and this function will search for a user account, then using the EmployeeID from that account it will find all related accounts (T0, T1, User)
         
        .PARAMETER SearchTerm
        Specifies the file name.
 
        .SYNTAX
 
        .INPUTS
        System.Object
            Properties
                SamAccountName (Active Directory Login Name)
                DistinguishedName (Active Directory Object Distinguished Name)
                EmployeeID (Team Member ID)
                mail (Email Address)
 
        System.String
            SearchTerm
                SamAccountName (Active Directory Login Name)
                DistinguishedName (Active Directory Object Distinguished Name)
                EmployeeID (Team Member ID)
                mail (Email Address)
 
        .OUTPUTS
        System.Object
            The found account
         
        [array]System.Object
            The list of found accounts
 
        .EXAMPLE
        PS> Get-UsersAccounts -SearchTerm ""
 
        .EXAMPLE
        PS> Get-UsersAccounts TMID
 
        .EXAMPLE
        PS> Get-UsersAccounts -SearchTerm ""
 
        .LINK
        Online version:
 
        .LINK
        Set-Item
    #>

    [cmdletBinding()]
    Param(
        [Parameter(
            ValueFromPipelineByPropertyName
        )]
        $EmployeeID,
        [Alias("SamAccountName", "DistinguishedName", "GUID", "SID", "EmployeeID", "mail", "UserPrincipalName")]
        $Identity = $ENV:USERNAME,
        [string[]]$Properties = @("Name", "EmployeeID", "physicalDeliveryOfficeName", "Title", "mail", "msRTCSIP-PrimaryUserAddress", "CanonicalName", "DistinguishedName", "samaccountname", "UserPrincipalname", "AccountExpirationDate", "Enabled", "Manager", "badPwdCount", "LastBadPasswordAttempt", "LockedOut", "LockOutTime", "lastLogonDate", "PasswordExpired", "PasswordLastSet", "whenCreated", "whenChanged"),
        [string[]]$Select = @("Name", "EmployeeID", "physicalDeliveryOfficeName", "Title", "mail", "msRTCSIP-PrimaryUserAddress", "CanonicalName", "DistinguishedName", "samaccountname", "UserPrincipalname", "AccountExpirationDate", "Enabled", "Manager", "badPwdCount", "LastBadPasswordAttempt", "LockedOut", "LockOutTime", "lastLogonDate", "PasswordExpired", "PasswordLastSet", "whenCreated", "whenChanged")
    )
    BEGIN { }
    PROCESS {
        If ($EmployeeID) {
            Write-Verbose "Searching $EmployeeID"
            Get-ADUser -Filter "EmployeeId -like '$EmployeeID*'" -Properties $Properties | Select-Object $Select
        }
        elseif ($Search) {
            foreach ($SearchTerm in $Identity) {
                Write-Verbose "Getting all accounts that match $SearchTerm"
                $Accounts = Get-ADUser -Filter "employeeid -eq '$SearchValue' -or SamAccountName -eq '$SearchValue' -or DistinguishedName -eq '$SearchValue' -or GUID -eq '$SearchValue' -or SID -eq '$SearchValue' -or EmployeeID -eq '$SearchValue' -or mail -eq '$SearchValue' -or UserPrincipalName -eq '$SearchValue'" -Properties $Properties | Select-Object $Select
                Foreach ($Account in $Accounts) {
                    $EmployeeID = $Account.EmployeeID
                    Get-ADUser -Filter "EmployeeId -like '$EmployeeID*'" -Properties $Properties | Select-Object $Select
                }
            }
        }
    }
    END { }
}