Private/Get-ADUserDetailsBasedOnDN.ps1

function Get-ADUserDetailsBasedOnDN {

    ################################################################################
    ##### #####
    ##### Find Demo Accounts based on AS2GoDemoUser Account Name Pattern #####
    ##### #####
    ################################################################################

    Param(
        [Parameter(Mandatory)]
        [string]$DN
    )

    $CurrentFunction = Get-FunctionName
    Write-Log -Message "### Start Function $CurrentFunction ###"
    $StartRunTime = (Get-Date).ToString($Script:DateFormatLog)
    #################### main code | out- host #####################

    $Server = Get-BestDomainController -Domain $dn
    Try {
        $results = Get-ADUser -Identity $DN -Properties * -Server $server -ErrorAction stop
        $user = [PSCustomObject]@{
            UPN            = $results.UserPrincipalName
            SID            = $results.objectSid.Value
            FQDN           = $results.CanonicalName.Split("/")[0]
            CN             = $results.CanonicalName
            samaccountname = $results.SamAccountName
            Enalbed        = $results.Enabled
            DN             = $results.DistinguishedName
        } 
    }
    Catch {
        Write-Log -Message " >> No user found for DN: $DN" -Level WARN
        $user = [PSCustomObject]@{
            UPN            = "Account Not Found"
            SID            = "Account Not Found"
            FQDN           = "Account Not Found"
            CN             = "Account Not Found"
            samaccountname = "Account Not Found"
            DN             = $DN
        }
    }  

    Write-Log -Message " >> Found $results Demo Account "
    ######################## main code ############################
    $runtime = Get-RunTime -StartRunTime $StartRunTime
    Write-Log -Message " Run Time: $runtime [h] ###"
    Write-Log -Message "### End Function $CurrentFunction ###"
    return $user
}