functions/utility/Resolve-Computer.ps1

function Resolve-Computer {
    <#
    .SYNOPSIS
        Resolves the DNS name of computers
     
    .DESCRIPTION
        Resolves the DNS name of computers
     
    .PARAMETER ComputerName
        The names of the computers to process.
        If DistinguishedNames are specified, it will look up the information from AD.
     
    .PARAMETER OU
        OU in which to search for computer accounts to resolve.
     
    .PARAMETER Filter
        Filter to apply to searches in an organizational unit.
        Only used together with '-OU'
        Defaults to: '*'
     
    .PARAMETER Server
        Server / Domain to contact for AD queries.
     
    .PARAMETER Credential
        Credentials to use for AD Queries
     
    .EXAMPLE
        PS C:\> Resolve-Computer -ComputerName $ComputerName
 
        Resolves the DNS-compatible names in $ComputerName
    #>

    [OutputType([string])]
    [CmdletBinding()]
    param (
        [PSFComputer[]]
        $ComputerName,

        [string]
        $OU,

        [string]
        $Filter = '*',

        [string]
        $Server,

        [pscredential]
        $Credential
    )

    $parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include Server, Credential

    foreach ($computer in $ComputerName) {
        if ($computer -notlike "*,DC=*") {
            # Resolves a lot of different formats, including
            $computer.ComputerName
            continue
        }

        (Get-ADComputer @parameters -Identity $computer).DNSHostName
    }

    if ($OU) {
        (Get-ADComputer @parameters -SearchBase $OU -Filter $Filter).DNSHostName
    }
}