function Get-Hostname ([string]$name) {
    Write-Progress -Activity "Resolving hostname for $name" -PercentComplete 0 -ParentId 1
    # Return early if the hostname already resolves
    if (Resolve-DnsName $name) { 
        Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
        return $name,''
    }
    Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Asset Tag Lookup' -PercentComplete 10 -ParentId 1
    $errMsg = ''
    if ($name.Length -eq 5) {
        $res = Get-AssetConversion $name 
        if ($res) { 
            Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
            return $res,'' 
        } else { $errMsg += "$name Asset Tag not in SMBIOS`n" }
        # We don't check CMDB asset tags here because they often resolve to 
        # something other than the hostname, like the asset tag itself
    }
    Write-Progress -Activity "Resolving hostname for $name" -Status 'IP Address resolution' -PercentComplete 20 -ParentId 1
    # Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050
    if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
        $res = Resolve-DnsName $name
        if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
            Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
            return $Matches[0],''
        } else {
            $errMsg += "$name IP Address couldn't be resolved to hostname`n"
        }
    }
    Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Serial Number lookup' -PercentComplete 30 -ParentId 1
    if ($name.Length -eq 7) {
        $res = Get-ServiceTagConversion $name 
        if ($res) { 
            Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
            return $res,'' 
        } else { $errMsg += "$name Service Tag not found in SCCM`n"}
    }
    Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM MAC Address lookup' -PercentComplete 40 -ParentId 1
    # Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512
    if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") {
        $res = Get-SCCM_PCFromMAC $name
        if ($res) { 
            Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
            return $res,'' 
        } else { $errMsg += "$name MAC Address not found in SCCM`n"}
    }

    # Last resort checks
    Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Hostname match' -PercentComplete 50 -ParentId 1
    $SCCMMatches = Get-SCCM_HostnameMatch $name
    if ($SCCMMatches -and $SCCMMatches.Count -lt 2) {
        Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
        return $SCCMMatches,''
    } elseif (!$SCCMMatches) { $errMsg += "No SCCM name match found`n" }
    elseif ($SCCMMatches.Count -ge 2) { $errMsg += "Many SCCM name matches found`n" }

    # CMDB check should be absolute last resort
    Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB General search' -PercentComplete 60 -ParentId 1
    $cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name
    if ($cmdbMatches -and $cmdbMatches.Count -lt 2) {
        Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
        return $cmdbMatches.Name,''
    } elseif (!$cmdbMatches) { $errMsg += "No CMDB name match found`n" }
    elseif ($cmdbMatches.Count -ge 2) { 
        # Try more specific queries
        # Asset tag
        Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB Asset Tag search' -PercentComplete 70 -ParentId 1
        if ($name.Length -eq 5) {
            try {
                $cmdbData = Search-ISMBO -bo cis -Filter "AssetTag eq '$name'" -RawFilter
            } catch { $cmdbData = $null }
            if ( $cmdbData ) { 
                if (Resolve-DnsName $cmdbData.Name) { 
                    Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
                    return $cmdbData.Name,'' 
                } else { $errMsg += "CMDB name associated with Asset tag $name doesn't resolve to IP Address"}
            } else { $errMsg += "Asset tag not in CMDB" }
        }
        Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB MAC Address search' -PercentComplete 80 -ParentId 1
        if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") {
            try {
                $cmdbData = Search-ISMBO -bo cis -Filter "MACAddress eq '$name'" -RawFilter
            } catch { $cmdbData = $null }
            if ( $cmdbData ) { 
                if (Resolve-DnsName $cmdbData.Name) { 
                    Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
                    return $cmdbData.Name,'' 
                } else { $errMsg += "CMDB name associated with MAC Address $name doesn't resolve to IP Address"}
            } else { $errMsg += "MAC Address not in CMDB" }
        }
        # Serial number
        Write-Progress -Activity "Resolving hostname for $name" -Status 'CMDB Serial Number search' -PercentComplete 80 -ParentId 1
        try {
            $cmdbData = Search-ISMBO -bo cis -Filter "SerialNumber eq '$name'" -RawFilter
        } catch { $cmdbData = $null }
        if ( $cmdbData ) { 
            if (Resolve-DnsName $cmdbData.Name) { 
                Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1
                return $cmdbData.Name,'' 
            } else { $errMsg += "CMDB name associated with Serial Number $name doesn't resolve to IP Address"}
        } else { $errMsg += "Serial Number not in CMDB" }
        $errMsg += "Many CMDB matches found`n" 
    }

    return $name, $errMsg
}